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

Side by Side Diff: apps/shell/shell_content_browser_client.cc

Issue 136453005: app_shell: Make renderer run background page JavaScript (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup (load_background_page) Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "apps/shell/shell_content_browser_client.h" 5 #include "apps/shell/shell_content_browser_client.h"
6 6
7 #include "apps/shell/shell_browser_context.h" 7 #include "apps/shell/shell_browser_context.h"
8 #include "apps/shell/shell_browser_main_parts.h" 8 #include "apps/shell/shell_browser_main_parts.h"
9 #include "apps/shell/shell_extension_system.h"
10 #include "base/command_line.h"
11 #include "chrome/browser/extensions/extension_protocols.h"
12 #include "chrome/browser/extensions/extension_resource_protocols.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/render_process_host.h"
16 #include "content/public/browser/site_instance.h"
17 #include "content/public/common/content_switches.h"
18 #include "content/public/common/url_constants.h"
9 #include "content/shell/browser/shell_browser_context.h" 19 #include "content/shell/browser/shell_browser_context.h"
20 #include "extensions/browser/extension_registry.h"
21 #include "extensions/browser/info_map.h"
22 #include "extensions/common/constants.h"
23 #include "extensions/common/extension.h"
24 #include "url/gurl.h"
25
26 using content::BrowserThread;
27 using extensions::ExtensionRegistry;
10 28
11 namespace apps { 29 namespace apps {
12 30
13 ShellContentBrowserClient::ShellContentBrowserClient() 31 ShellContentBrowserClient::ShellContentBrowserClient()
14 : browser_main_parts_(NULL) { 32 : browser_main_parts_(NULL) {
15 } 33 }
16 34
17 ShellContentBrowserClient::~ShellContentBrowserClient() { 35 ShellContentBrowserClient::~ShellContentBrowserClient() {
18 } 36 }
19 37
20 content::BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( 38 content::BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts(
21 const content::MainFunctionParams& parameters) { 39 const content::MainFunctionParams& parameters) {
22 browser_main_parts_ = new ShellBrowserMainParts(parameters); 40 browser_main_parts_ = new ShellBrowserMainParts(parameters);
23 return browser_main_parts_; 41 return browser_main_parts_;
24 } 42 }
25 43
26 net::URLRequestContextGetter* 44 net::URLRequestContextGetter*
27 ShellContentBrowserClient::CreateRequestContext( 45 ShellContentBrowserClient::CreateRequestContext(
28 content::BrowserContext* content_browser_context, 46 content::BrowserContext* content_browser_context,
29 content::ProtocolHandlerMap* protocol_handlers) { 47 content::ProtocolHandlerMap* protocol_handlers) {
30 // TODO(jamescook): Should this be an off-the-record context? 48 // Handle chrome-extension: and chrome-extension-resource: requests.
49 extensions::InfoMap* extension_info_map =
50 browser_main_parts_->extension_system()->info_map();
51 (*protocol_handlers)[extensions::kExtensionScheme] =
James Cook 2014/01/15 18:49:27 This is equivalent to the way Chrome registers the
52 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>(
53 CreateExtensionProtocolHandler(false /*is_incognito*/,
54 extension_info_map));
55 (*protocol_handlers)[extensions::kExtensionResourceScheme] =
56 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>(
57 CreateExtensionResourceProtocolHandler());
58 // Let content::ShellBrowserContext handle the rest of the setup.
31 return browser_main_parts_->browser_context()->CreateRequestContext( 59 return browser_main_parts_->browser_context()->CreateRequestContext(
32 protocol_handlers); 60 protocol_handlers);
33 } 61 }
34 62
63 bool ShellContentBrowserClient::IsHandledURL(const GURL& url) {
64 if (!url.is_valid())
65 return false;
66 // Keep in sync with ProtocolHandlers added in CreateRequestContext() and in
67 // content::ShellURLRequestContextGetter::GetURLRequestContext().
68 static const char* const kProtocolList[] = {
69 chrome::kBlobScheme,
70 chrome::kChromeUIScheme,
71 chrome::kChromeDevToolsScheme,
72 chrome::kDataScheme,
73 content::kFileScheme,
74 content::kFileSystemScheme,
75 extensions::kExtensionScheme,
76 extensions::kExtensionResourceScheme,
77 };
78 for (size_t i = 0; i < arraysize(kProtocolList); ++i) {
79 if (url.scheme() == kProtocolList[i])
80 return true;
81 }
82 return false;
83 }
84
85 void ShellContentBrowserClient::SiteInstanceGotProcess(
86 content::SiteInstance* site_instance) {
87 // If this isn't an extension renderer there's nothing to do.
88 const extensions::Extension* extension = GetExtension(site_instance);
89 if (!extension)
90 return;
91
92 // TODO(jamescook): Add to extension service process_map().
93
94 BrowserThread::PostTask(
95 BrowserThread::IO,
96 FROM_HERE,
97 base::Bind(&extensions::InfoMap::RegisterExtensionProcess,
98 browser_main_parts_->extension_system()->info_map(),
99 extension->id(),
100 site_instance->GetProcess()->GetID(),
101 site_instance->GetId()));
102 }
103
104 void ShellContentBrowserClient::SiteInstanceDeleting(
105 content::SiteInstance* site_instance) {
106 // If this isn't an extension renderer there's nothing to do.
107 const extensions::Extension* extension = GetExtension(site_instance);
108 if (!extension)
109 return;
110
111 // TODO(jamescook): Remove from extension service process_map().
112
113 BrowserThread::PostTask(
114 BrowserThread::IO,
115 FROM_HERE,
116 base::Bind(&extensions::InfoMap::UnregisterExtensionProcess,
117 browser_main_parts_->extension_system()->info_map(),
118 extension->id(),
119 site_instance->GetProcess()->GetID(),
120 site_instance->GetId()));
121 }
122
123 void ShellContentBrowserClient::AppendExtraCommandLineSwitches(
124 CommandLine* command_line, int child_process_id) {
125 std::string process_type =
126 command_line->GetSwitchValueASCII(switches::kProcessType);
127 if (process_type == switches::kRendererProcess) {
128 // TODO(jamescook): Should we check here if the process is in the extension
129 // service process map, or can we assume all renderers are extension
Yoyo Zhou 2014/01/16 01:44:11 Assuming this is probably ok until we learn otherw
130 // renderers?
131 command_line->AppendSwitch(switches::kExtensionProcess);
132 }
133 }
134
135 const extensions::Extension* ShellContentBrowserClient::GetExtension(
136 content::SiteInstance* site_instance) {
137 ExtensionRegistry* registry =
138 ExtensionRegistry::Get(site_instance->GetBrowserContext());
139 return registry->enabled_extensions().GetExtensionOrAppByURL(
140 site_instance->GetSiteURL());
141 }
142
35 } // namespace apps 143 } // namespace apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698