OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "android_webview/browser/renderer_host/aw_render_view_host_ext.h" | 5 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" |
6 | 6 |
7 #include "android_webview/common/render_view_messages.h" | 7 #include "android_webview/common/render_view_messages.h" |
8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "content/public/browser/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
12 #include "content/public/browser/user_metrics.h" | 12 #include "content/public/browser/user_metrics.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 #include "content/public/common/frame_navigate_params.h" | |
14 | 15 |
15 namespace android_webview { | 16 namespace android_webview { |
16 | 17 |
17 AwRenderViewHostExt::AwRenderViewHostExt(content::WebContents* contents, | 18 AwRenderViewHostExt::AwRenderViewHostExt(content::WebContents* contents, |
18 Client* client) | 19 Client* client) |
19 : content::WebContentsObserver(contents), | 20 : content::WebContentsObserver(contents), |
20 has_new_hit_test_data_(false), | 21 has_new_hit_test_data_(false), |
22 visitedlink_master_(contents->GetBrowserContext(), this), | |
21 client_(client) { | 23 client_(client) { |
24 visitedlink_master_.Init(); | |
25 | |
26 // TODO(boliu): Add option to master so it never writes or rebuilds from | |
27 // disk then remove this and the one in the destructor. The app handles | |
28 // persistencing these urls. | |
mkosiba (inactive)
2013/01/14 11:56:20
nit: persisting
| |
29 visitedlink_master_.DeleteAllURLs(); | |
22 } | 30 } |
23 | 31 |
24 AwRenderViewHostExt::~AwRenderViewHostExt() {} | 32 AwRenderViewHostExt::~AwRenderViewHostExt() { |
33 visitedlink_master_.DeleteAllURLs(); | |
34 } | |
25 | 35 |
26 void AwRenderViewHostExt::DocumentHasImages(DocumentHasImagesResult result) { | 36 void AwRenderViewHostExt::DocumentHasImages(DocumentHasImagesResult result) { |
27 DCHECK(CalledOnValidThread()); | 37 DCHECK(CalledOnValidThread()); |
28 if (!web_contents()->GetRenderViewHost()) { | 38 if (!web_contents()->GetRenderViewHost()) { |
29 result.Run(false); | 39 result.Run(false); |
30 return; | 40 return; |
31 } | 41 } |
32 static int next_id = 1; | 42 static int next_id = 1; |
33 int this_id = next_id++; | 43 int this_id = next_id++; |
34 pending_document_has_images_requests_[this_id] = result; | 44 pending_document_has_images_requests_[this_id] = result; |
(...skipping 29 matching lines...) Expand all Loading... | |
64 void AwRenderViewHostExt::RenderViewGone(base::TerminationStatus status) { | 74 void AwRenderViewHostExt::RenderViewGone(base::TerminationStatus status) { |
65 DCHECK(CalledOnValidThread()); | 75 DCHECK(CalledOnValidThread()); |
66 for (std::map<int, DocumentHasImagesResult>::iterator pending_req = | 76 for (std::map<int, DocumentHasImagesResult>::iterator pending_req = |
67 pending_document_has_images_requests_.begin(); | 77 pending_document_has_images_requests_.begin(); |
68 pending_req != pending_document_has_images_requests_.end(); | 78 pending_req != pending_document_has_images_requests_.end(); |
69 ++pending_req) { | 79 ++pending_req) { |
70 pending_req->second.Run(false); | 80 pending_req->second.Run(false); |
71 } | 81 } |
72 } | 82 } |
73 | 83 |
84 void AwRenderViewHostExt::DidNavigateAnyFrame( | |
85 const content::LoadCommittedDetails& details, | |
86 const content::FrameNavigateParams& params) { | |
87 DCHECK(CalledOnValidThread()); | |
88 | |
89 visitedlink_master_.AddURL(params.base_url); | |
90 } | |
91 | |
74 bool AwRenderViewHostExt::OnMessageReceived(const IPC::Message& message) { | 92 bool AwRenderViewHostExt::OnMessageReceived(const IPC::Message& message) { |
75 bool handled = true; | 93 bool handled = true; |
76 IPC_BEGIN_MESSAGE_MAP(AwRenderViewHostExt, message) | 94 IPC_BEGIN_MESSAGE_MAP(AwRenderViewHostExt, message) |
77 IPC_MESSAGE_HANDLER(AwViewHostMsg_DocumentHasImagesResponse, | 95 IPC_MESSAGE_HANDLER(AwViewHostMsg_DocumentHasImagesResponse, |
78 OnDocumentHasImagesResponse) | 96 OnDocumentHasImagesResponse) |
79 IPC_MESSAGE_HANDLER(AwViewHostMsg_UpdateHitTestData, | 97 IPC_MESSAGE_HANDLER(AwViewHostMsg_UpdateHitTestData, |
80 OnUpdateHitTestData) | 98 OnUpdateHitTestData) |
81 IPC_MESSAGE_HANDLER(AwViewHostMsg_PictureUpdated, | 99 IPC_MESSAGE_HANDLER(AwViewHostMsg_PictureUpdated, |
82 OnPictureUpdated) | 100 OnPictureUpdated) |
83 IPC_MESSAGE_UNHANDLED(handled = false) | 101 IPC_MESSAGE_UNHANDLED(handled = false) |
84 IPC_END_MESSAGE_MAP() | 102 IPC_END_MESSAGE_MAP() |
85 | 103 |
86 return handled ? true : WebContentsObserver::OnMessageReceived(message); | 104 return handled ? true : WebContentsObserver::OnMessageReceived(message); |
87 } | 105 } |
88 | 106 |
107 bool AwRenderViewHostExt::AreEquivalentContexts( | |
108 content::BrowserContext* context1, | |
109 content::BrowserContext* context2) { | |
110 DCHECK(CalledOnValidThread()); | |
111 | |
112 // Raw pointer comparison since Android WebView does not have sub-contexts | |
113 // like incognito. | |
114 return context1 == context2; | |
115 } | |
116 | |
117 void AwRenderViewHostExt::RebuildTable( | |
118 const scoped_refptr<URLEnumerator>& enumerator) { | |
119 DCHECK(CalledOnValidThread()); | |
120 | |
121 // Android WebView rebuilds from WebChromeClient which can change in the | |
122 // lifetime of this WebView and may not yet be set here. This initialization | |
123 // path is not used. | |
124 enumerator->OnComplete(true); | |
125 } | |
126 | |
89 void AwRenderViewHostExt::OnDocumentHasImagesResponse(int msg_id, | 127 void AwRenderViewHostExt::OnDocumentHasImagesResponse(int msg_id, |
90 bool has_images) { | 128 bool has_images) { |
91 DCHECK(CalledOnValidThread()); | 129 DCHECK(CalledOnValidThread()); |
92 std::map<int, DocumentHasImagesResult>::iterator pending_req = | 130 std::map<int, DocumentHasImagesResult>::iterator pending_req = |
93 pending_document_has_images_requests_.find(msg_id); | 131 pending_document_has_images_requests_.find(msg_id); |
94 if (pending_req == pending_document_has_images_requests_.end()) { | 132 if (pending_req == pending_document_has_images_requests_.end()) { |
95 DLOG(WARNING) << "unexpected DocumentHasImages Response: " << msg_id; | 133 DLOG(WARNING) << "unexpected DocumentHasImages Response: " << msg_id; |
96 } else { | 134 } else { |
97 pending_req->second.Run(has_images); | 135 pending_req->second.Run(has_images); |
98 pending_document_has_images_requests_.erase(pending_req); | 136 pending_document_has_images_requests_.erase(pending_req); |
99 } | 137 } |
100 } | 138 } |
101 | 139 |
102 void AwRenderViewHostExt::OnUpdateHitTestData( | 140 void AwRenderViewHostExt::OnUpdateHitTestData( |
103 const AwHitTestData& hit_test_data) { | 141 const AwHitTestData& hit_test_data) { |
104 DCHECK(CalledOnValidThread()); | 142 DCHECK(CalledOnValidThread()); |
105 last_hit_test_data_ = hit_test_data; | 143 last_hit_test_data_ = hit_test_data; |
106 has_new_hit_test_data_ = true; | 144 has_new_hit_test_data_ = true; |
107 } | 145 } |
108 | 146 |
109 void AwRenderViewHostExt::OnPictureUpdated() { | 147 void AwRenderViewHostExt::OnPictureUpdated() { |
110 if (client_) | 148 if (client_) |
111 client_->OnPictureUpdated(web_contents()->GetRenderProcessHost()->GetID(), | 149 client_->OnPictureUpdated(web_contents()->GetRenderProcessHost()->GetID(), |
112 routing_id()); | 150 routing_id()); |
113 } | 151 } |
114 | 152 |
115 } // namespace android_webview | 153 } // namespace android_webview |
OLD | NEW |