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

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: Fix problems with attaching guest view, add extension function dispatcher 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..fedba8fe8e86b9a28d593bbdf386cc1b6c20d38b
--- /dev/null
+++ b/chrome/browser/guest_view/extension_options/extension_options_guest.cc
@@ -0,0 +1,93 @@
+// 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/guest_view/extension_options/extension_options_constants.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 "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() {}
+
+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));
+}
+
+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);
+ DCHECK(!extension_id.empty());
Fady Samuel 2014/07/11 21:08:05 if (extension_id.empty())) { callback.Run(NULL);
ericzeng 2014/07/12 00:10:04 Done.
+ GURL extensionUrl =
Fady Samuel 2014/07/11 21:08:05 extension_url
ericzeng 2014/07/12 00:10:04 Done.
+ extensions::Extension::GetBaseURLFromExtensionId(extension_id);
Fady Samuel 2014/07/11 21:08:05 Check that this URL is valid. I would be surprised
ericzeng 2014/07/12 00:10:04 Done.
+
+ // 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);
Fady Samuel 2014/07/11 21:08:05 We should probably fail if this extension doesn't
ericzeng 2014/07/12 00:10:04 Done.
+
+ // Create a Webcontents using the extension URL
Fady Samuel 2014/07/11 21:08:05 The options page should live in the same process a
+ content::SiteInstance* options_site_instance =
+ content::SiteInstance::CreateForURL(browser_context, extensionUrl);
+ WebContents::CreateParams params(browser_context,
+ options_site_instance);
+ params.guest_delegate = this;
+ callback.Run(WebContents::Create(params));
+}
+
+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