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

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

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

Powered by Google App Engine
This is Rietveld 408576698