summaryrefslogtreecommitdiffstats
path: root/extensions/browser/app_window
diff options
context:
space:
mode:
authorrdevlin.cronin <rdevlin.cronin@chromium.org>2015-07-09 10:36:59 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-09 17:37:20 +0000
commitc3d6ba1b13ec1f050178e4f97c121b528c07520d (patch)
treef635cdcaf99a8e2abf7507c227e1e2038d733f1d /extensions/browser/app_window
parent58b04162d300a4c9b067cf281c83823094c0aeb5 (diff)
downloadchromium_src-c3d6ba1b13ec1f050178e4f97c121b528c07520d.zip
chromium_src-c3d6ba1b13ec1f050178e4f97c121b528c07520d.tar.gz
chromium_src-c3d6ba1b13ec1f050178e4f97c121b528c07520d.tar.bz2
[Extensions OOPI] Update app window bindings for OOPI
Update the app window custom bindings to use render frame logic instead of render view logic. This involves changes to the custom bindings themselves, as well as app window creation logic. And, for fun, a few small cleanups while I was in the area. BUG=455776 TBR=dbeam@chromium.org (webui) Review URL: https://codereview.chromium.org/1211003006 Cr-Commit-Position: refs/heads/master@{#338076}
Diffstat (limited to 'extensions/browser/app_window')
-rw-r--r--extensions/browser/app_window/app_window_contents.cc14
-rw-r--r--extensions/browser/app_window/app_window_contents.h4
-rw-r--r--extensions/browser/app_window/app_window_registry.cc56
-rw-r--r--extensions/browser/app_window/app_window_registry.h19
4 files changed, 38 insertions, 55 deletions
diff --git a/extensions/browser/app_window/app_window_contents.cc b/extensions/browser/app_window/app_window_contents.cc
index 8d8c9ae..e2e0e29 100644
--- a/extensions/browser/app_window/app_window_contents.cc
+++ b/extensions/browser/app_window/app_window_contents.cc
@@ -44,12 +44,12 @@ void AppWindowContentsImpl::LoadContents(int32 creator_process_id) {
// RVH from loading anything until the background page has had a chance to
// do any initialization it wants. If it's a different process, the new RVH
// shouldn't communicate with the background page anyway (e.g. sandboxed).
- if (web_contents_->GetRenderViewHost()->GetProcess()->GetID() ==
+ if (web_contents_->GetMainFrame()->GetProcess()->GetID() ==
creator_process_id) {
- SuspendRenderViewHost(web_contents_->GetRenderViewHost());
+ SuspendRenderFrameHost(web_contents_->GetMainFrame());
} else {
VLOG(1) << "AppWindow created in new process ("
- << web_contents_->GetRenderViewHost()->GetProcess()->GetID()
+ << web_contents_->GetMainFrame()->GetProcess()->GetID()
<< ") != creator (" << creator_process_id << "). Routing disabled.";
}
@@ -107,14 +107,14 @@ void AppWindowContentsImpl::UpdateDraggableRegions(
host_->UpdateDraggableRegions(regions);
}
-void AppWindowContentsImpl::SuspendRenderViewHost(
- content::RenderViewHost* rvh) {
- DCHECK(rvh);
+void AppWindowContentsImpl::SuspendRenderFrameHost(
+ content::RenderFrameHost* rfh) {
+ DCHECK(rfh);
content::BrowserThread::PostTask(
content::BrowserThread::IO, FROM_HERE,
base::Bind(&content::ResourceDispatcherHost::BlockRequestsForRoute,
base::Unretained(content::ResourceDispatcherHost::Get()),
- rvh->GetProcess()->GetID(), rvh->GetRoutingID()));
+ rfh->GetProcess()->GetID(), rfh->GetRoutingID()));
}
} // namespace extensions
diff --git a/extensions/browser/app_window/app_window_contents.h b/extensions/browser/app_window/app_window_contents.h
index 56c1664..608b987 100644
--- a/extensions/browser/app_window/app_window_contents.h
+++ b/extensions/browser/app_window/app_window_contents.h
@@ -7,13 +7,13 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
-#include "content/public/browser/notification_observer.h"
#include "content/public/browser/web_contents_observer.h"
#include "extensions/browser/app_window/app_window.h"
#include "url/gurl.h"
namespace content {
class BrowserContext;
+class RenderFrameHost;
}
namespace extensions {
@@ -43,7 +43,7 @@ class AppWindowContentsImpl : public AppWindowContents,
bool OnMessageReceived(const IPC::Message& message) override;
void UpdateDraggableRegions(const std::vector<DraggableRegion>& regions);
- void SuspendRenderViewHost(content::RenderViewHost* rvh);
+ void SuspendRenderFrameHost(content::RenderFrameHost* rfh);
AppWindow* host_; // This class is owned by |host_|
GURL url_;
diff --git a/extensions/browser/app_window/app_window_registry.cc b/extensions/browser/app_window/app_window_registry.cc
index d072499..e5c9497 100644
--- a/extensions/browser/app_window/app_window_registry.cc
+++ b/extensions/browser/app_window/app_window_registry.cc
@@ -7,11 +7,11 @@
#include <string>
#include <vector>
+#include "base/strings/stringprintf.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/render_process_host.h"
-#include "content/public/browser/render_view_host.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/app_window/app_window.h"
@@ -21,32 +21,6 @@
namespace extensions {
-namespace {
-
-// Create a key that identifies a AppWindow in a RenderViewHost across App
-// reloads. If the window was given an id in CreateParams, the key is the
-// extension id, a colon separator, and the AppWindow's |id|. If there is no
-// |id|, the chrome-extension://extension-id/page.html URL will be used. If the
-// RenderViewHost is not for a AppWindow, return an empty string.
-std::string GetWindowKeyForRenderViewHost(
- const AppWindowRegistry* registry,
- content::RenderViewHost* render_view_host) {
- AppWindow* app_window =
- registry->GetAppWindowForRenderViewHost(render_view_host);
- if (!app_window)
- return std::string(); // Not a AppWindow.
-
- if (app_window->window_key().empty())
- return app_window->web_contents()->GetURL().possibly_invalid_spec();
-
- std::string key = app_window->extension_id();
- key += ':';
- key += app_window->window_key();
- return key;
-}
-
-} // namespace
-
void AppWindowRegistry::Observer::OnAppWindowAdded(AppWindow* app_window) {
}
@@ -148,7 +122,7 @@ void AppWindowRegistry::CloseAllAppWindowsForApp(const std::string& app_id) {
}
AppWindow* AppWindowRegistry::GetAppWindowForWebContents(
- content::WebContents* web_contents) const {
+ const content::WebContents* web_contents) const {
for (AppWindow* window : app_windows_) {
if (window->web_contents() == web_contents)
return window;
@@ -156,12 +130,6 @@ AppWindow* AppWindowRegistry::GetAppWindowForWebContents(
return nullptr;
}
-AppWindow* AppWindowRegistry::GetAppWindowForRenderViewHost(
- content::RenderViewHost* render_view_host) const {
- return GetAppWindowForWebContents(
- content::WebContents::FromRenderViewHost(render_view_host));
-}
-
AppWindow* AppWindowRegistry::GetAppWindowForNativeWindow(
gfx::NativeWindow window) const {
for (AppWindowList::const_iterator i = app_windows_.begin();
@@ -207,8 +175,8 @@ AppWindow* AppWindowRegistry::GetAppWindowForAppAndKey(
}
bool AppWindowRegistry::HadDevToolsAttached(
- content::RenderViewHost* render_view_host) const {
- std::string key = GetWindowKeyForRenderViewHost(this, render_view_host);
+ content::WebContents* web_contents) const {
+ std::string key = GetWindowKeyForWebContents(web_contents);
return key.empty() ? false : inspected_windows_.count(key) != 0;
}
@@ -220,8 +188,7 @@ void AppWindowRegistry::OnDevToolsStateChanged(
if (!web_contents || web_contents->GetBrowserContext() != context_)
return;
- std::string key =
- GetWindowKeyForRenderViewHost(this, web_contents->GetRenderViewHost());
+ std::string key = GetWindowKeyForWebContents(web_contents);
if (key.empty())
return;
@@ -247,6 +214,19 @@ void AppWindowRegistry::BringToFront(AppWindow* app_window) {
app_windows_.push_front(app_window);
}
+std::string AppWindowRegistry::GetWindowKeyForWebContents(
+ content::WebContents* web_contents) const {
+ AppWindow* app_window = GetAppWindowForWebContents(web_contents);
+ if (!app_window)
+ return std::string(); // Not an AppWindow.
+
+ if (app_window->window_key().empty())
+ return web_contents->GetURL().possibly_invalid_spec();
+
+ return base::StringPrintf("%s:%s", app_window->extension_id().c_str(),
+ app_window->window_key().c_str());
+}
+
///////////////////////////////////////////////////////////////////////////////
// Factory boilerplate
diff --git a/extensions/browser/app_window/app_window_registry.h b/extensions/browser/app_window/app_window_registry.h
index 486a6fc..6d5ba85 100644
--- a/extensions/browser/app_window/app_window_registry.h
+++ b/extensions/browser/app_window/app_window_registry.h
@@ -20,7 +20,6 @@
namespace content {
class BrowserContext;
class DevToolsAgentHost;
-class RenderViewHost;
class WebContents;
}
@@ -85,11 +84,7 @@ class AppWindowRegistry : public KeyedService {
// Helper functions to find app windows with particular attributes.
AppWindow* GetAppWindowForWebContents(
- content::WebContents* web_contents) const;
- // TODO(devlin): Remove this when callers have been updated to use the
- // above.
- AppWindow* GetAppWindowForRenderViewHost(
- content::RenderViewHost* render_view_host) const;
+ const content::WebContents* web_contents) const;
AppWindow* GetAppWindowForNativeWindow(gfx::NativeWindow window) const;
// Returns an app window for the given app, or NULL if no app windows are
// open. If there is a window for the given app that is active, that one will
@@ -104,8 +99,8 @@ class AppWindowRegistry : public KeyedService {
// Returns whether a AppWindow's ID was last known to have a DevToolsAgent
// attached to it, which should be restored during a reload of a corresponding
- // newly created |render_view_host|.
- bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const;
+ // newly created |web_contents|.
+ bool HadDevToolsAttached(content::WebContents* web_contents) const;
class Factory : public BrowserContextKeyedServiceFactory {
public:
@@ -142,6 +137,14 @@ class AppWindowRegistry : public KeyedService {
// list, add it first.
void BringToFront(AppWindow* app_window);
+ // Create a key that identifies an AppWindow across App reloads. If the window
+ // was given an id in CreateParams, the key is the extension id, a colon
+ // separator, and the AppWindow's |id|. If there is no |id|, the
+ // chrome-extension://extension-id/page.html URL will be used. If the
+ // WebContents is not for a AppWindow, return an empty string.
+ std::string GetWindowKeyForWebContents(
+ content::WebContents* web_contents) const;
+
content::BrowserContext* context_;
AppWindowList app_windows_;
InspectedWindowSet inspected_windows_;