Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1247)

Unified Diff: chrome/browser/guest_view/extension_options/extension_options_guest.cc

Issue 378783002: Initial implementation of the <extensionoptions> GuestView tag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restructure tests again Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/guest_view/extension_options/extension_options_guest.cc
diff --git a/chrome/browser/guest_view/extension_options/extension_options_guest.cc b/chrome/browser/guest_view/extension_options/extension_options_guest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fcebc94ac87f0c1154e887371227a4bb702b75b5
--- /dev/null
+++ b/chrome/browser/guest_view/extension_options/extension_options_guest.cc
@@ -0,0 +1,125 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/guest_view/extension_options/extension_options_guest.h"
+
+#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
+#include "chrome/browser/guest_view/extension_options/extension_options_constants.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/extensions/manifest_url_handler.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/site_instance.h"
+#include "content/public/browser/web_contents.h"
+#include "extensions/browser/extension_function_dispatcher.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/common/extension.h"
+#include "extensions/common/extension_messages.h"
+#include "extensions/common/permissions/permissions_data.h"
+#include "ipc/ipc_message_macros.h"
+
+using content::WebContents;
+
+// static
+const char ExtensionOptionsGuest::Type[] = "extensionoptions";
+
+ExtensionOptionsGuest::ExtensionOptionsGuest(
+ content::BrowserContext* browser_context,
+ int guest_instance_id)
+ : GuestView<ExtensionOptionsGuest>(browser_context, guest_instance_id) {
+}
+
+ExtensionOptionsGuest::~ExtensionOptionsGuest() {
+}
+
+bool ExtensionOptionsGuest::CanEmbedderUseGuestView(
+ const std::string& embedder_extension_id) {
+ const extensions::Extension* embedder_extension =
+ extensions::ExtensionRegistry::Get(browser_context())
+ ->enabled_extensions()
+ .GetByID(embedder_extension_id);
+ if (embedder_extension) {
Fady Samuel 2014/07/21 12:48:56 nit: you can avoid a block as follows (I feel this
ericzeng 2014/07/21 17:52:39 Done.
+ return embedder_extension->permissions_data()->HasAPIPermission(
+ extensions::APIPermission::kEmbeddedExtensionOptions);
+ }
+ return false;
+}
+
+void ExtensionOptionsGuest::CreateWebContents(
+ const std::string& embedder_extension_id,
+ int embedder_render_process_id,
+ const base::DictionaryValue& create_params,
+ const WebContentsCreatedCallback& callback) {
+ content::BrowserContext* browser_context =
Fady Samuel 2014/07/21 12:48:56 Hmm, is this necessary? A GuestView should know ab
ericzeng 2014/07/21 17:52:39 Done.
+ content::RenderProcessHost::FromID(embedder_render_process_id)
+ ->GetBrowserContext();
+
+ // Get the extension's base URL.
+ std::string extension_id;
+ create_params.GetString(extensionoptions::kExtensionId, &extension_id);
+ if (extension_id.empty()) {
+ callback.Run(NULL);
+ return;
+ }
+ DCHECK(extensions::Extension::IdIsValid(extension_id));
+
+ GURL extension_url =
+ extensions::Extension::GetBaseURLFromExtensionId(extension_id);
+ if (!extension_url.is_valid()) {
+ callback.Run(NULL);
+ return;
+ }
+
+ // Get the options page URL for later use.
+ extensions::ExtensionRegistry* registry =
+ extensions::ExtensionRegistry::Get(browser_context);
+ const extensions::Extension* extension =
+ registry->enabled_extensions().GetByID(extension_id);
+ options_page_ = extensions::ManifestURL::GetOptionsPage(extension);
+ if (!options_page_.is_valid()) {
+ callback.Run(NULL);
+ return;
+ }
+
+ // Create a Webcontents using the extension URL. The options page's
Fady Samuel 2014/07/21 12:48:56 s/Webcontents/WebContents
ericzeng 2014/07/21 17:52:39 Done.
+ // WebContents should live in the same process as its parent extension's
+ // WebContents, so we can use |extension_url| for creating the SiteInstance.
+ content::SiteInstance* options_site_instance =
+ content::SiteInstance::CreateForURL(browser_context, extension_url);
+ WebContents::CreateParams params(browser_context, options_site_instance);
+ params.guest_delegate = this;
+ callback.Run(WebContents::Create(params));
+}
+
+void ExtensionOptionsGuest::DidAttachToEmbedder() {
+ guest_web_contents()->GetController().LoadURL(options_page_,
+ content::Referrer(),
+ content::PAGE_TRANSITION_LINK,
+ std::string());
+}
+
+void ExtensionOptionsGuest::DidInitialize() {
+ extension_function_dispatcher_.reset(
+ new extensions::ExtensionFunctionDispatcher(browser_context(), this));
+ extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
+ guest_web_contents());
+}
+
+content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const {
+ return guest_web_contents();
+}
+
+bool ExtensionOptionsGuest::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(ExtensionOptionsGuest, message)
+ IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void ExtensionOptionsGuest::OnRequest(
+ const ExtensionHostMsg_Request_Params& params) {
+ extension_function_dispatcher_->Dispatch(
+ params, guest_web_contents()->GetRenderViewHost());
+}

Powered by Google App Engine
This is Rietveld 408576698