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

Unified Diff: chrome/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc

Issue 376033002: Adding MimeHandlerView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pending-zork-patch2
Patch Set: sync @tott 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/mime_handler_view/mime_handler_view_guest.cc
diff --git a/chrome/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc b/chrome/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..39057c3380c59eb956ae70659f34a5423cf8e9a4
--- /dev/null
+++ b/chrome/browser/guest_view/mime_handler_view/mime_handler_view_guest.cc
@@ -0,0 +1,106 @@
+// 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/mime_handler_view/mime_handler_view_guest.h"
+
+#include "base/strings/stringprintf.h"
+#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
+#include "chrome/browser/guest_view/guest_view_manager.h"
+#include "chrome/browser/guest_view/web_view/web_view_renderer_state.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/common/url_constants.h"
+
+using content::WebContents;
+
+// static
+const char MimeHandlerViewGuest::Type[] = "mimehandler";
+
+MimeHandlerViewGuest::MimeHandlerViewGuest(
+ content::BrowserContext* browser_context,
+ int guest_instance_id)
+ : GuestView<MimeHandlerViewGuest>(
+ browser_context, guest_instance_id),
+ has_navigated_(false) {
Fady Samuel 2014/07/21 14:47:35 Get rid of this flag.
lazyboy 2014/07/21 17:28:21 Done.
+}
+
+MimeHandlerViewGuest::~MimeHandlerViewGuest() {
+}
+
+bool MimeHandlerViewGuest::CanEmbedderUseGuestView(
+ const std::string& embedder_extension_id) {
+ return true;
+}
+void MimeHandlerViewGuest::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 =
Fady Samuel 2014/07/21 14:47:35 This doesn't seem necessary, you can simply use br
lazyboy 2014/07/21 17:28:21 Done.
+ content::RenderProcessHost::FromID(embedder_render_process_id);
+
+ GURL guest_site(base::StringPrintf("%s://%s/",
+ content::kGuestScheme,
+ embedder_extension_id.c_str()));
+
+ // If we already have a webview tag in the same app using the same storage
+ // partition, we should use the same SiteInstance so the existing tag and
+ // the new tag can script each other.
+ GuestViewManager* guest_view_manager =
+ GuestViewManager::FromBrowserContext(
+ embedder_render_process_host->GetBrowserContext());
+ content::SiteInstance* guest_site_instance =
+ guest_view_manager->GetGuestSiteInstance(guest_site);
+ if (!guest_site_instance) {
+ // Create the SiteInstance in a new BrowsingInstance, which will ensure
+ // that webview tags are also not allowed to send messages across
Fady Samuel 2014/07/21 14:47:35 This comment doesn't make sense for MimeHandlerVie
lazyboy 2014/07/21 17:28:21 I've reworded the comments.
+ // different partitions.
+ guest_site_instance = content::SiteInstance::CreateForURL(
+ embedder_render_process_host->GetBrowserContext(), guest_site);
+ }
+ WebContents::CreateParams params(
+ embedder_render_process_host->GetBrowserContext(),
+ guest_site_instance);
+ params.guest_delegate = this;
+ callback.Run(WebContents::Create(params));
+}
+
+void MimeHandlerViewGuest::DidAttachToEmbedder() {
+ has_navigated_ = false;
Fady Samuel 2014/07/21 14:47:35 This flag seems unnecessary.
lazyboy 2014/07/21 17:28:21 Done.
+ std::string src;
+ if (extra_params()->GetString("src", &src) && !src.empty())
Fady Samuel 2014/07/21 14:47:35 Make src a constant.
lazyboy 2014/07/21 17:28:20 Done.
+ NavigateGuest(src);
+
+ DCHECK(!GetOpener());
Fady Samuel 2014/07/21 14:47:35 Why is this DCHECK important?
lazyboy 2014/07/21 17:28:20 It's not, copy paste stuff, removed.
+}
+
+void MimeHandlerViewGuest::DidInitialize() {
+ AttachWebContentsHelpers(guest_web_contents());
+}
+
+void MimeHandlerViewGuest::AttachWebContentsHelpers(
+ content::WebContents* contents) {
+ // Required for ExtensionHostMsg_PostMessage.
+ extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
+ contents);
+}
+
+void MimeHandlerViewGuest::NavigateGuest(const std::string& src) {
+ if (has_navigated_)
+ return;
+
+ has_navigated_ = true;
+ GURL validated_url(src);
+ guest_web_contents()->GetRenderProcessHost()->
+ FilterURL(false, &validated_url);
+ // As guests do not swap processes on navigation, only navigations to
+ // normal web URLs are supported. No protocol handlers are installed for
+ // other schemes (e.g., WebUI or extensions), and no permissions or bindings
+ // can be granted to the guest process.
+ content::NavigationController::LoadURLParams load_url_params(validated_url);
+ load_url_params.referrer = content::Referrer();
+ load_url_params.transition_type = content::PAGE_TRANSITION_AUTO_TOPLEVEL;
+ load_url_params.extra_headers = std::string();
+ guest_web_contents()->GetController().LoadURLWithParams(load_url_params);
Fady Samuel 2014/07/21 14:47:35 This seems unnecessary. Why can't it be something
lazyboy 2014/07/21 17:28:21 That's simpler, thanks. Done.
+}

Powered by Google App Engine
This is Rietveld 408576698