OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/guest_view/guest_view_base.h" | 5 #include "chrome/browser/guest_view/guest_view_base.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/guest_view/app_view/app_view_guest.h" | 10 #include "chrome/browser/guest_view/app_view/app_view_guest.h" |
11 #include "chrome/browser/guest_view/extension_options/extension_options_guest.h" | |
11 #include "chrome/browser/guest_view/guest_view_constants.h" | 12 #include "chrome/browser/guest_view/guest_view_constants.h" |
12 #include "chrome/browser/guest_view/guest_view_manager.h" | 13 #include "chrome/browser/guest_view/guest_view_manager.h" |
13 #include "chrome/browser/guest_view/web_view/web_view_guest.h" | 14 #include "chrome/browser/guest_view/web_view/web_view_guest.h" |
14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/content_settings.h" | 16 #include "chrome/common/content_settings.h" |
16 #include "content/public/browser/render_frame_host.h" | 17 #include "content/public/browser/render_frame_host.h" |
17 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
18 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
20 #include "content/public/common/url_constants.h" | 21 #include "content/public/common/url_constants.h" |
21 #include "extensions/browser/event_router.h" | 22 #include "extensions/browser/event_router.h" |
23 #include "extensions/common/switches.h" | |
22 #include "third_party/WebKit/public/web/WebInputEvent.h" | 24 #include "third_party/WebKit/public/web/WebInputEvent.h" |
23 | 25 |
24 using content::WebContents; | 26 using content::WebContents; |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 typedef std::map<WebContents*, GuestViewBase*> WebContentsGuestViewMap; | 30 typedef std::map<WebContents*, GuestViewBase*> WebContentsGuestViewMap; |
29 static base::LazyInstance<WebContentsGuestViewMap> webcontents_guestview_map = | 31 static base::LazyInstance<WebContentsGuestViewMap> webcontents_guestview_map = |
30 LAZY_INSTANCE_INITIALIZER; | 32 LAZY_INSTANCE_INITIALIZER; |
31 | 33 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 | 139 |
138 // Give the derived class an opportunity to perform additional initialization. | 140 // Give the derived class an opportunity to perform additional initialization. |
139 DidInitialize(); | 141 DidInitialize(); |
140 } | 142 } |
141 | 143 |
142 // static | 144 // static |
143 GuestViewBase* GuestViewBase::Create( | 145 GuestViewBase* GuestViewBase::Create( |
144 content::BrowserContext* browser_context, | 146 content::BrowserContext* browser_context, |
145 int guest_instance_id, | 147 int guest_instance_id, |
146 const std::string& view_type) { | 148 const std::string& view_type) { |
149 // TODO(fsamuel): All these string comparisons are a little inefficient. Maybe | |
150 // we want a registry of GuestView types in the future. | |
147 if (view_type == WebViewGuest::Type) { | 151 if (view_type == WebViewGuest::Type) { |
148 return new WebViewGuest(browser_context, guest_instance_id); | 152 return new WebViewGuest(browser_context, guest_instance_id); |
149 } else if (view_type == AppViewGuest::Type) { | 153 } else if (view_type == AppViewGuest::Type) { |
150 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 154 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
151 switches::kEnableAppView)) { | 155 switches::kEnableAppView)) { |
152 return NULL; | 156 return NULL; |
153 } | 157 } |
154 return new AppViewGuest(browser_context, guest_instance_id); | 158 return new AppViewGuest(browser_context, guest_instance_id); |
159 } else if (view_type == ExtensionOptionsGuest::Type) { | |
160 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
Devlin
2014/07/16 20:55:07
Feature switch it up.
ericzeng
2014/07/16 22:27:38
Done.
| |
161 extensions::switches::kEnableEmbeddedExtensionOptions)) { | |
162 return NULL; | |
163 } | |
164 return new ExtensionOptionsGuest(browser_context, guest_instance_id); | |
155 } | 165 } |
156 NOTREACHED(); | 166 NOTREACHED(); |
157 return NULL; | 167 return NULL; |
158 } | 168 } |
159 | 169 |
160 // static | 170 // static |
161 GuestViewBase* GuestViewBase::FromWebContents(WebContents* web_contents) { | 171 GuestViewBase* GuestViewBase::FromWebContents(WebContents* web_contents) { |
162 WebContentsGuestViewMap* guest_map = webcontents_guestview_map.Pointer(); | 172 WebContentsGuestViewMap* guest_map = webcontents_guestview_map.Pointer(); |
163 WebContentsGuestViewMap::iterator it = guest_map->find(web_contents); | 173 WebContentsGuestViewMap::iterator it = guest_map->find(web_contents); |
164 return it == guest_map->end() ? NULL : it->second; | 174 return it == guest_map->end() ? NULL : it->second; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 // purpose. Let's self-destruct. | 374 // purpose. Let's self-destruct. |
365 delete this; | 375 delete this; |
366 callback.Run(NULL); | 376 callback.Run(NULL); |
367 return; | 377 return; |
368 } | 378 } |
369 InitWithWebContents(embedder_extension_id, | 379 InitWithWebContents(embedder_extension_id, |
370 embedder_render_process_id, | 380 embedder_render_process_id, |
371 guest_web_contents); | 381 guest_web_contents); |
372 callback.Run(guest_web_contents); | 382 callback.Run(guest_web_contents); |
373 } | 383 } |
OLD | NEW |