예제 #1
0
PBrowserParent*
nsIContentParent::AllocPBrowserParent(const TabId& aTabId,
                                      const TabId& aSameTabGroupAs,
                                      const IPCTabContext& aContext,
                                      const uint32_t& aChromeFlags,
                                      const ContentParentId& aCpId,
                                      const bool& aIsForBrowser)
{
  MOZ_ASSERT(!aSameTabGroupAs);

  Unused << aCpId;
  Unused << aIsForBrowser;

  if (!CanOpenBrowser(aContext)) {
    return nullptr;
  }

  uint32_t chromeFlags = aChromeFlags;
  TabId openerTabId(0);
  ContentParentId openerCpId(0);
  if (aContext.type() == IPCTabContext::TPopupIPCTabContext) {
    // CanOpenBrowser has ensured that the IPCTabContext is of
    // type PopupIPCTabContext, and that the opener TabParent is
    // reachable.
    const PopupIPCTabContext& popupContext = aContext.get_PopupIPCTabContext();
    auto opener = TabParent::GetFrom(popupContext.opener().get_PBrowserParent());
    openerTabId = opener->GetTabId();
    openerCpId = opener->Manager()->ChildID();

    // We must ensure that the private browsing and remoteness flags
    // match those of the opener.
    nsCOMPtr<nsILoadContext> loadContext = opener->GetLoadContext();
    if (!loadContext) {
      return nullptr;
    }

    bool isPrivate;
    loadContext->GetUsePrivateBrowsing(&isPrivate);
    if (isPrivate) {
      chromeFlags |= nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW;
    }
  }

  if (openerTabId > 0 ||
      aContext.type() == IPCTabContext::TUnsafeIPCTabContext) {
    // Creation of PBrowser triggered from grandchild process is currently
    // broken and not supported (i.e. this code path doesn't work in
    // ContentBridgeParent).
    //
    // If you're working on fixing the code path for ContentBridgeParent,
    // remember to handle the remote frame registration below carefully as it
    // has to be registered in parent process.
    MOZ_ASSERT(XRE_IsParentProcess());
    if (!XRE_IsParentProcess()) {
      return nullptr;
    }

    // The creation of PBrowser was triggered from content process through
    // either window.open() or service worker's openWindow().
    // We need to register remote frame with the child generated tab id.
    ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
    if (!cpm->RegisterRemoteFrame(aTabId, openerCpId, openerTabId, aContext, aCpId)) {
      return nullptr;
    }
  }

  // And because we're allocating a remote browser, of course the
  // window is remote.
  chromeFlags |= nsIWebBrowserChrome::CHROME_REMOTE_WINDOW;

  MaybeInvalidTabContext tc(aContext);
  MOZ_ASSERT(tc.IsValid());
  TabParent* parent = new TabParent(this, aTabId, tc.GetTabContext(), chromeFlags);

  // We release this ref in DeallocPBrowserParent()
  NS_ADDREF(parent);
  return parent;
}
예제 #2
0
/* virtual */ ES_GetState
DOM_BrowserTab::GetName(OpAtom property_name, ES_Value* value, ES_Runtime* origining_runtime)
{
	switch (property_name)
	{
	case OP_ATOM_id:
		DOMSetNumber(value, GetTabId());
		return GET_SUCCESS;

	case OP_ATOM_locked:
	case OP_ATOM_browserWindow:
	case OP_ATOM_position:
	case OP_ATOM_tabGroup:
	case OP_ATOM_focused:
	case OP_ATOM_selected:
	case OP_ATOM_title:
	case OP_ATOM_private:
	case OP_ATOM_closed:
		return GetTabInfo(property_name, value, origining_runtime, NULL);

	case OP_ATOM_faviconUrl:
	{
#ifdef SHORTCUT_ICON_SUPPORT
		Window* window = GetTabWindow();
		if (window && (!window->GetPrivacyMode() || IsPrivateDataAllowed()))
			DOMSetString(value, window->GetWindowIconURL().GetAttribute(URL::KUniName_With_Fragment, URL::KNoRedirect).CStr());
#endif // SHORTCUT_ICON_SUPPORT
		return GET_SUCCESS;
	}

	case OP_ATOM_url:
	{
		Window* window = GetTabWindow();
		if (window && (!window->GetPrivacyMode() || IsPrivateDataAllowed()))
		{
			const uni_char* url = window->GetCurrentURL().GetAttribute(URL::KUniName_With_Fragment, URL::KNoRedirect).CStr();
			if (!url || !*url) // if nothing is currently loaded then try if something is loading.
				url = window->GetCurrentLoadingURL().GetAttribute(URL::KUniName_With_Fragment, URL::KNoRedirect).CStr();
			DOMSetString(value, url);
		}
		return GET_SUCCESS;
	}

	case OP_ATOM_readyState:
	{
		Window* window = GetTabWindow();
		if (window && (!window->GetPrivacyMode() || IsPrivateDataAllowed()))
			DOM_Document::GetDocumentReadiness(value, window->GetCurrentDoc());
		return GET_SUCCESS;
	}
#ifdef USE_SPDY
	case OP_ATOM_loadedWithSPDY:
	{
		Window* window = GetTabWindow();
		if (window && (!window->GetPrivacyMode() || IsPrivateDataAllowed()))
			DOMSetBoolean(value, window->GetCurrentURL().GetAttribute(URL::KLoadedWithSpdy));
		return GET_SUCCESS;
	}
#endif // USE_SPDY
	case OP_ATOM_port:
		DOMSetObject(value, GetPort());
		return GET_SUCCESS;

	default:
		return DOM_Object::GetName(property_name, value, origining_runtime);
	}
}
예제 #3
0
/* virtual */
DOM_BrowserTab::~DOM_BrowserTab()
{
	OP_NEW_DBG("DOM_BrowserTab::~DOM_BrowserTab()", "extensions.dom");
	OP_DBG(("this: %p tab_id: %d", this, GetTabId()));
}
예제 #4
0
ES_GetState
DOM_BrowserTab::GetTabInfo(OpAtom property_name, ES_Value* value, ES_Runtime* origining_runtime, ES_Object* restart_object)
{
	if (!value)
		return GET_SUCCESS;

	// Private mode can be obtained synchronously if we have window.
	if (property_name == OP_ATOM_private)
	{
		Window* window = GetTabWindow();
		if (window)
		{
			DOMSetBoolean(value, window->GetPrivacyMode());
			return GET_SUCCESS;
		}
	}

	OP_ASSERT(GetTabId());

	DOM_TabsApiHelper* call_helper;
	if (!restart_object)
	{
		GET_FAILED_IF_ERROR(DOM_TabsApiHelper::Make(call_helper, static_cast<DOM_Runtime*>(origining_runtime)));
		call_helper->QueryTab(GetTabId());
	}
	else
		call_helper = DOM_HOSTOBJECT(restart_object, DOM_TabsApiHelper);

	if (call_helper->IsFinished())
	{
		if (property_name == OP_ATOM_closed)
		{
			DOMSetBoolean(value, OpStatus::IsError(call_helper->GetStatus()));
			return GET_SUCCESS;
		}
		else
			GET_FAILED_IF_ERROR(call_helper->GetStatus());

		switch (property_name)
		{
		case OP_ATOM_browserWindow:
			DOM_BrowserWindow* new_win;
			GET_FAILED_IF_ERROR(DOM_TabApiCache::GetOrCreateWindow(new_win, m_extension_support, call_helper->GetResult().value.query_tab.browser_window_id, GetRuntime()));
			DOMSetObject(value, new_win);
			break;
		case OP_ATOM_locked:
			DOMSetBoolean(value, call_helper->GetResult().value.query_tab.is_locked);
			break;
		case OP_ATOM_position:
			DOMSetNumber(value, call_helper->GetResult().value.query_tab.position);
			break;
		case OP_ATOM_tabGroup:
			if (call_helper->GetResult().value.query_tab.tab_group_id == 0)
				DOMSetNull(value);
			else
			{
				DOM_BrowserTabGroup* tab_group;
				GET_FAILED_IF_ERROR(DOM_TabApiCache::GetOrCreateTabGroup(tab_group, m_extension_support, call_helper->GetResult().value.query_tab.tab_group_id, GetRuntime()));
				DOMSetObject(value, tab_group);
			}
			break;
		case OP_ATOM_focused:
		case OP_ATOM_selected:
			DOMSetBoolean(value, call_helper->GetResult().value.query_tab.is_selected);
			break;

		case OP_ATOM_title:
			if (!call_helper->GetResult().value.query_tab.is_private || IsPrivateDataAllowed())
			{
				TempBuffer* tmp = GetEmptyTempBuf();
				GET_FAILED_IF_ERROR(tmp->Append(call_helper->GetResult().value.query_tab.title));
				DOMSetString(value, tmp);
			}
			return GET_SUCCESS;

		case OP_ATOM_private:
			DOMSetBoolean(value, call_helper->GetResult().value.query_tab.is_private);
			return GET_SUCCESS;

		default:
			OP_ASSERT(!"Unexpected property");
		}
		return GET_SUCCESS;
	}
	else
		return call_helper->BlockGet(value, origining_runtime);
}