OLD | NEW |
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 "chrome/browser/guestview/guestview.h" | 5 #include "chrome/browser/guestview/guestview.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "chrome/browser/extensions/event_router.h" | 8 #include "chrome/browser/extensions/event_router.h" |
9 #include "chrome/browser/guestview/adview/adview_guest.h" | 9 #include "chrome/browser/guestview/adview/adview_guest.h" |
10 #include "chrome/browser/guestview/guestview_constants.h" | 10 #include "chrome/browser/guestview/guestview_constants.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 args_(args.Pass()) { | 34 args_(args.Pass()) { |
35 } | 35 } |
36 | 36 |
37 GuestView::Event::~Event() { | 37 GuestView::Event::~Event() { |
38 } | 38 } |
39 | 39 |
40 scoped_ptr<DictionaryValue> GuestView::Event::GetArguments() { | 40 scoped_ptr<DictionaryValue> GuestView::Event::GetArguments() { |
41 return args_.Pass(); | 41 return args_.Pass(); |
42 } | 42 } |
43 | 43 |
44 GuestView::GuestView(WebContents* guest_web_contents) | 44 GuestView::GuestView(WebContents* guest_web_contents, |
| 45 const std::string& extension_id) |
45 : guest_web_contents_(guest_web_contents), | 46 : guest_web_contents_(guest_web_contents), |
46 embedder_web_contents_(NULL), | 47 embedder_web_contents_(NULL), |
| 48 extension_id_(extension_id), |
47 embedder_render_process_id_(0), | 49 embedder_render_process_id_(0), |
48 browser_context_(guest_web_contents->GetBrowserContext()), | 50 browser_context_(guest_web_contents->GetBrowserContext()), |
49 guest_instance_id_(guest_web_contents->GetEmbeddedInstanceID()), | 51 guest_instance_id_(guest_web_contents->GetEmbeddedInstanceID()), |
50 view_instance_id_(guestview::kInstanceIDNone) { | 52 view_instance_id_(guestview::kInstanceIDNone) { |
51 webcontents_guestview_map.Get().insert( | 53 webcontents_guestview_map.Get().insert( |
52 std::make_pair(guest_web_contents, this)); | 54 std::make_pair(guest_web_contents, this)); |
53 } | 55 } |
54 | 56 |
55 // static | 57 // static |
56 GuestView::Type GuestView::GetViewTypeFromString(const std::string& api_type) { | 58 GuestView::Type GuestView::GetViewTypeFromString(const std::string& api_type) { |
57 if (api_type == "adview") { | 59 if (api_type == "adview") { |
58 return GuestView::ADVIEW; | 60 return GuestView::ADVIEW; |
59 } else if (api_type == "webview") { | 61 } else if (api_type == "webview") { |
60 return GuestView::WEBVIEW; | 62 return GuestView::WEBVIEW; |
61 } | 63 } |
62 return GuestView::UNKNOWN; | 64 return GuestView::UNKNOWN; |
63 } | 65 } |
64 | 66 |
65 // static | 67 // static |
66 GuestView* GuestView::Create(WebContents* guest_web_contents, | 68 GuestView* GuestView::Create(WebContents* guest_web_contents, |
| 69 const std::string& extension_id, |
67 GuestView::Type view_type) { | 70 GuestView::Type view_type) { |
68 switch (view_type) { | 71 switch (view_type) { |
69 case GuestView::WEBVIEW: | 72 case GuestView::WEBVIEW: |
70 return new WebViewGuest(guest_web_contents); | 73 return new WebViewGuest(guest_web_contents, extension_id); |
71 case GuestView::ADVIEW: | 74 case GuestView::ADVIEW: |
72 return new AdViewGuest(guest_web_contents); | 75 return new AdViewGuest(guest_web_contents, extension_id); |
73 default: | 76 default: |
74 NOTREACHED(); | 77 NOTREACHED(); |
75 return NULL; | 78 return NULL; |
76 } | 79 } |
77 } | 80 } |
78 | 81 |
79 // static | 82 // static |
80 GuestView* GuestView::FromWebContents(WebContents* web_contents) { | 83 GuestView* GuestView::FromWebContents(WebContents* web_contents) { |
81 WebContentsGuestViewMap* guest_map = webcontents_guestview_map.Pointer(); | 84 WebContentsGuestViewMap* guest_map = webcontents_guestview_map.Pointer(); |
82 WebContentsGuestViewMap::iterator it = guest_map->find(web_contents); | 85 WebContentsGuestViewMap::iterator it = guest_map->find(web_contents); |
83 return it == guest_map->end() ? NULL : it->second; | 86 return it == guest_map->end() ? NULL : it->second; |
84 } | 87 } |
85 | 88 |
86 // static | 89 // static |
87 GuestView* GuestView::From(int embedder_process_id, int guest_instance_id) { | 90 GuestView* GuestView::From(int embedder_process_id, int guest_instance_id) { |
88 EmbedderGuestViewMap* guest_map = embedder_guestview_map.Pointer(); | 91 EmbedderGuestViewMap* guest_map = embedder_guestview_map.Pointer(); |
89 EmbedderGuestViewMap::iterator it = guest_map->find( | 92 EmbedderGuestViewMap::iterator it = guest_map->find( |
90 std::make_pair(embedder_process_id, guest_instance_id)); | 93 std::make_pair(embedder_process_id, guest_instance_id)); |
91 return it == guest_map->end() ? NULL : it->second; | 94 return it == guest_map->end() ? NULL : it->second; |
92 } | 95 } |
93 | 96 |
94 void GuestView::Attach(content::WebContents* embedder_web_contents, | 97 void GuestView::Attach(content::WebContents* embedder_web_contents, |
95 const std::string& extension_id, | |
96 const base::DictionaryValue& args) { | 98 const base::DictionaryValue& args) { |
97 embedder_web_contents_ = embedder_web_contents; | 99 embedder_web_contents_ = embedder_web_contents; |
98 embedder_render_process_id_ = | 100 embedder_render_process_id_ = |
99 embedder_web_contents->GetRenderProcessHost()->GetID(); | 101 embedder_web_contents->GetRenderProcessHost()->GetID(); |
100 extension_id_ = extension_id; | |
101 args.GetInteger(guestview::kParameterInstanceId, &view_instance_id_); | 102 args.GetInteger(guestview::kParameterInstanceId, &view_instance_id_); |
102 | 103 |
103 std::pair<int, int> key(embedder_render_process_id_, guest_instance_id_); | 104 std::pair<int, int> key(embedder_render_process_id_, guest_instance_id_); |
104 embedder_guestview_map.Get().insert(std::make_pair(key, this)); | 105 embedder_guestview_map.Get().insert(std::make_pair(key, this)); |
105 | 106 |
106 // GuestView::Attach is called prior to initialization (and initial | 107 // GuestView::Attach is called prior to initialization (and initial |
107 // navigation) of the guest in the content layer in order to permit mapping | 108 // navigation) of the guest in the content layer in order to permit mapping |
108 // the necessary associations between the <*view> element and its guest. This | 109 // the necessary associations between the <*view> element and its guest. This |
109 // is needed by the <webview> WebRequest API to allow intercepting resource | 110 // is needed by the <webview> WebRequest API to allow intercepting resource |
110 // requests during navigation. However, queued events should be fired after | 111 // requests during navigation. However, queued events should be fired after |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 void GuestView::SendQueuedEvents() { | 166 void GuestView::SendQueuedEvents() { |
166 if (!attached()) | 167 if (!attached()) |
167 return; | 168 return; |
168 | 169 |
169 while (!pending_events_.empty()) { | 170 while (!pending_events_.empty()) { |
170 Event* event = pending_events_.front(); | 171 Event* event = pending_events_.front(); |
171 pending_events_.pop(); | 172 pending_events_.pop(); |
172 DispatchEvent(event); | 173 DispatchEvent(event); |
173 } | 174 } |
174 } | 175 } |
OLD | NEW |