| 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" | |
| 8 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/guest_view/app_view/app_view_guest.h" | 9 #include "chrome/browser/guest_view/app_view/app_view_guest.h" |
| 11 #include "chrome/browser/guest_view/guest_view_constants.h" | 10 #include "chrome/browser/guest_view/guest_view_constants.h" |
| 12 #include "chrome/browser/guest_view/guest_view_manager.h" | 11 #include "chrome/browser/guest_view/guest_view_manager.h" |
| 13 #include "chrome/browser/guest_view/web_view/web_view_guest.h" | 12 #include "chrome/browser/guest_view/web_view/web_view_guest.h" |
| 14 #include "chrome/common/chrome_switches.h" | |
| 15 #include "chrome/common/content_settings.h" | 13 #include "chrome/common/content_settings.h" |
| 16 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
| 17 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
| 18 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/url_constants.h" | 18 #include "content/public/common/url_constants.h" |
| 21 #include "extensions/browser/event_router.h" | 19 #include "extensions/browser/event_router.h" |
| 22 #include "third_party/WebKit/public/web/WebInputEvent.h" | 20 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 23 | 21 |
| 24 using content::WebContents; | 22 using content::WebContents; |
| 25 | 23 |
| 26 namespace { | 24 namespace { |
| 27 | 25 |
| 26 typedef std::map<std::string, GuestViewBase::GuestCreationCallback> |
| 27 GuestViewCreationMap; |
| 28 static base::LazyInstance<GuestViewCreationMap> guest_view_registry = |
| 29 LAZY_INSTANCE_INITIALIZER; |
| 30 |
| 28 typedef std::map<WebContents*, GuestViewBase*> WebContentsGuestViewMap; | 31 typedef std::map<WebContents*, GuestViewBase*> WebContentsGuestViewMap; |
| 29 static base::LazyInstance<WebContentsGuestViewMap> webcontents_guestview_map = | 32 static base::LazyInstance<WebContentsGuestViewMap> webcontents_guestview_map = |
| 30 LAZY_INSTANCE_INITIALIZER; | 33 LAZY_INSTANCE_INITIALIZER; |
| 31 | 34 |
| 32 } // namespace | 35 } // namespace |
| 33 | 36 |
| 34 GuestViewBase::Event::Event(const std::string& name, | 37 GuestViewBase::Event::Event(const std::string& name, |
| 35 scoped_ptr<base::DictionaryValue> args) | 38 scoped_ptr<base::DictionaryValue> args) |
| 36 : name_(name), args_(args.Pass()) { | 39 : name_(name), args_(args.Pass()) { |
| 37 } | 40 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 webcontents_guestview_map.Get().insert( | 136 webcontents_guestview_map.Get().insert( |
| 134 std::make_pair(guest_web_contents, this)); | 137 std::make_pair(guest_web_contents, this)); |
| 135 GuestViewManager::FromBrowserContext(browser_context_)-> | 138 GuestViewManager::FromBrowserContext(browser_context_)-> |
| 136 AddGuest(guest_instance_id_, guest_web_contents); | 139 AddGuest(guest_instance_id_, guest_web_contents); |
| 137 | 140 |
| 138 // Give the derived class an opportunity to perform additional initialization. | 141 // Give the derived class an opportunity to perform additional initialization. |
| 139 DidInitialize(); | 142 DidInitialize(); |
| 140 } | 143 } |
| 141 | 144 |
| 142 // static | 145 // static |
| 146 void GuestViewBase::RegisterGuestViewTypes() { |
| 147 GuestView<WebViewGuest>::Register(); |
| 148 GuestView<AppViewGuest>::Register(); |
| 149 } |
| 150 |
| 151 // static |
| 152 void GuestViewBase::RegisterGuestViewType( |
| 153 const std::string& view_type, |
| 154 const GuestCreationCallback& callback) { |
| 155 GuestViewCreationMap::iterator it = |
| 156 guest_view_registry.Get().find(view_type); |
| 157 DCHECK(it == guest_view_registry.Get().end()); |
| 158 guest_view_registry.Get()[view_type] = callback; |
| 159 } |
| 160 |
| 161 // static |
| 143 GuestViewBase* GuestViewBase::Create( | 162 GuestViewBase* GuestViewBase::Create( |
| 144 content::BrowserContext* browser_context, | 163 content::BrowserContext* browser_context, |
| 145 int guest_instance_id, | 164 int guest_instance_id, |
| 146 const std::string& view_type) { | 165 const std::string& view_type) { |
| 147 if (view_type == WebViewGuest::Type) { | 166 GuestViewCreationMap::iterator it = |
| 148 return new WebViewGuest(browser_context, guest_instance_id); | 167 guest_view_registry.Get().find(view_type); |
| 149 } else if (view_type == AppViewGuest::Type) { | 168 if (it == guest_view_registry.Get().end()) { |
| 150 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 169 NOTREACHED(); |
| 151 switches::kEnableAppView)) { | 170 return NULL; |
| 152 return NULL; | |
| 153 } | |
| 154 return new AppViewGuest(browser_context, guest_instance_id); | |
| 155 } | 171 } |
| 156 NOTREACHED(); | 172 return it->second.Run(browser_context, guest_instance_id); |
| 157 return NULL; | |
| 158 } | 173 } |
| 159 | 174 |
| 160 // static | 175 // static |
| 161 GuestViewBase* GuestViewBase::FromWebContents(WebContents* web_contents) { | 176 GuestViewBase* GuestViewBase::FromWebContents(WebContents* web_contents) { |
| 162 WebContentsGuestViewMap* guest_map = webcontents_guestview_map.Pointer(); | 177 WebContentsGuestViewMap* guest_map = webcontents_guestview_map.Pointer(); |
| 163 WebContentsGuestViewMap::iterator it = guest_map->find(web_contents); | 178 WebContentsGuestViewMap::iterator it = guest_map->find(web_contents); |
| 164 return it == guest_map->end() ? NULL : it->second; | 179 return it == guest_map->end() ? NULL : it->second; |
| 165 } | 180 } |
| 166 | 181 |
| 167 // static | 182 // static |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 // purpose. Let's self-destruct. | 379 // purpose. Let's self-destruct. |
| 365 delete this; | 380 delete this; |
| 366 callback.Run(NULL); | 381 callback.Run(NULL); |
| 367 return; | 382 return; |
| 368 } | 383 } |
| 369 InitWithWebContents(embedder_extension_id, | 384 InitWithWebContents(embedder_extension_id, |
| 370 embedder_render_process_id, | 385 embedder_render_process_id, |
| 371 guest_web_contents); | 386 guest_web_contents); |
| 372 callback.Run(guest_web_contents); | 387 callback.Run(guest_web_contents); |
| 373 } | 388 } |
| OLD | NEW |