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

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: Address Devlin's comments, modify tests 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..cfef97235524c9c18aa04ac8ff2c0c2549af7f9a
--- /dev/null
+++ b/chrome/browser/guest_view/extension_options/extension_options_guest.cc
@@ -0,0 +1,121 @@
+// 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/extension_service.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/browser/extension_system.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) {
+ Profile* profile = Profile::FromBrowserContext(browser_context());
+ ExtensionService* service =
+ extensions::ExtensionSystem::Get(profile)->extension_service();
+ const extensions::Extension* embedder_extension =
+ service->GetExtensionById(embedder_extension_id, false);
+ const extensions::PermissionsData* permissions_data =
+ embedder_extension->permissions_data();
+ return permissions_data->HasAPIPermission(
+ extensions::APIPermission::kEmbeddedExtensionOptions);
+}
+
+void ExtensionOptionsGuest::CreateWebContents(
+ const std::string& embedder_extension_id,
+ int embedder_render_process_id,
+ const base::DictionaryValue& create_params,
+ const WebContentsCreatedCallback& callback) {
+ content::RenderProcessHost* embedder_render_process_host =
+ content::RenderProcessHost::FromID(embedder_render_process_id);
+ content::BrowserContext* browser_context =
+ embedder_render_process_host->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;
+ }
+ 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->GetExtensionById(extension_id,
+ extensions::ExtensionRegistry::ENABLED);
+ options_page_ = extensions::ManifestURL::GetOptionsPage(extension);
+ if (!options_page_.is_valid()) {
+ callback.Run(NULL);
+ return;
+ }
+
+ // Create a Webcontents using the extension URL
+ 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() {
not at google - send to devlin 2014/07/16 00:10:57 you need to create an instance of a ChromeExtensio
ericzeng 2014/07/16 01:52:01 Done.
not at google - send to devlin 2014/07/21 16:30:43 you don't need this anymore, I fixed the bug which
ericzeng 2014/07/21 17:52:39 Apparently not, I can't run any of the chrome.test
+ extension_function_dispatcher_.reset(
+ new extensions::ExtensionFunctionDispatcher(browser_context(), this));
+}
+
+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