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 "chrome/renderer/chrome_render_view_observer.h" | 5 #include "chrome/renderer/chrome_render_view_observer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 OnSetClientSidePhishingDetection(true); | 187 OnSetClientSidePhishingDetection(true); |
188 } | 188 } |
189 | 189 |
190 ChromeRenderViewObserver::~ChromeRenderViewObserver() { | 190 ChromeRenderViewObserver::~ChromeRenderViewObserver() { |
191 } | 191 } |
192 | 192 |
193 bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { | 193 bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { |
194 bool handled = true; | 194 bool handled = true; |
195 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) | 195 IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) |
196 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript) | 196 IPC_MESSAGE_HANDLER(ChromeViewMsg_WebUIJavaScript, OnWebUIJavaScript) |
| 197 IPC_MESSAGE_HANDLER(ChromeViewMsg_CaptureSnapshot, OnCaptureSnapshot) |
197 IPC_MESSAGE_HANDLER(ChromeViewMsg_HandleMessageFromExternalHost, | 198 IPC_MESSAGE_HANDLER(ChromeViewMsg_HandleMessageFromExternalHost, |
198 OnHandleMessageFromExternalHost) | 199 OnHandleMessageFromExternalHost) |
199 IPC_MESSAGE_HANDLER(ChromeViewMsg_JavaScriptStressTestControl, | 200 IPC_MESSAGE_HANDLER(ChromeViewMsg_JavaScriptStressTestControl, |
200 OnJavaScriptStressTestControl) | 201 OnJavaScriptStressTestControl) |
201 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent, | 202 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent, |
202 OnSetAllowDisplayingInsecureContent) | 203 OnSetAllowDisplayingInsecureContent) |
203 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowRunningInsecureContent, | 204 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowRunningInsecureContent, |
204 OnSetAllowRunningInsecureContent) | 205 OnSetAllowRunningInsecureContent) |
205 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, | 206 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, |
206 OnSetClientSidePhishingDetection) | 207 OnSetClientSidePhishingDetection) |
(...skipping 21 matching lines...) Expand all Loading... |
228 const string16& jscript, | 229 const string16& jscript, |
229 int id, | 230 int id, |
230 bool notify_result) { | 231 bool notify_result) { |
231 webui_javascript_.reset(new WebUIJavaScript()); | 232 webui_javascript_.reset(new WebUIJavaScript()); |
232 webui_javascript_->frame_xpath = frame_xpath; | 233 webui_javascript_->frame_xpath = frame_xpath; |
233 webui_javascript_->jscript = jscript; | 234 webui_javascript_->jscript = jscript; |
234 webui_javascript_->id = id; | 235 webui_javascript_->id = id; |
235 webui_javascript_->notify_result = notify_result; | 236 webui_javascript_->notify_result = notify_result; |
236 } | 237 } |
237 | 238 |
| 239 void ChromeRenderViewObserver::OnCaptureSnapshot() { |
| 240 SkBitmap snapshot; |
| 241 bool error = false; |
| 242 |
| 243 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
| 244 if (!main_frame) |
| 245 error = true; |
| 246 |
| 247 if (!error && !CaptureSnapshot(render_view()->GetWebView(), &snapshot)) |
| 248 error = true; |
| 249 |
| 250 DCHECK(error == snapshot.empty()) << |
| 251 "Snapshot should be empty on error, non-empty otherwise."; |
| 252 |
| 253 // Send the snapshot to the browser process. |
| 254 Send(new ChromeViewHostMsg_Snapshot(routing_id(), snapshot)); |
| 255 } |
| 256 |
238 void ChromeRenderViewObserver::OnHandleMessageFromExternalHost( | 257 void ChromeRenderViewObserver::OnHandleMessageFromExternalHost( |
239 const std::string& message, | 258 const std::string& message, |
240 const std::string& origin, | 259 const std::string& origin, |
241 const std::string& target) { | 260 const std::string& target) { |
242 if (message.empty()) | 261 if (message.empty()) |
243 return; | 262 return; |
244 GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin, | 263 GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin, |
245 target); | 264 target); |
246 } | 265 } |
247 | 266 |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 // partial word indexed at the end that might have been clipped. Therefore, | 788 // partial word indexed at the end that might have been clipped. Therefore, |
770 // terminate the string at the last space to ensure no words are clipped. | 789 // terminate the string at the last space to ensure no words are clipped. |
771 if (contents->size() == kMaxIndexChars) { | 790 if (contents->size() == kMaxIndexChars) { |
772 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16); | 791 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16); |
773 if (last_space_index == std::wstring::npos) | 792 if (last_space_index == std::wstring::npos) |
774 return; // don't index if we got a huge block of text with no spaces | 793 return; // don't index if we got a huge block of text with no spaces |
775 contents->resize(last_space_index); | 794 contents->resize(last_space_index); |
776 } | 795 } |
777 } | 796 } |
778 | 797 |
| 798 bool ChromeRenderViewObserver::CaptureSnapshot(WebView* view, |
| 799 SkBitmap* snapshot) { |
| 800 base::TimeTicks beginning_time = base::TimeTicks::Now(); |
| 801 |
| 802 view->layout(); |
| 803 const WebSize& size = view->size(); |
| 804 |
| 805 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef( |
| 806 skia::CreatePlatformCanvas( |
| 807 size.width, size.height, true, NULL, skia::RETURN_NULL_ON_FAILURE)); |
| 808 if (!canvas) |
| 809 return false; |
| 810 |
| 811 view->paint(webkit_glue::ToWebCanvas(canvas.get()), |
| 812 WebRect(0, 0, size.width, size.height)); |
| 813 // TODO: Add a way to snapshot the whole page, not just the currently |
| 814 // visible part. |
| 815 |
| 816 SkDevice* device = skia::GetTopDevice(*canvas); |
| 817 |
| 818 const SkBitmap& bitmap = device->accessBitmap(false); |
| 819 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config)) |
| 820 return false; |
| 821 |
| 822 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot", |
| 823 base::TimeTicks::Now() - beginning_time); |
| 824 return true; |
| 825 } |
| 826 |
779 ExternalHostBindings* ChromeRenderViewObserver::GetExternalHostBindings() { | 827 ExternalHostBindings* ChromeRenderViewObserver::GetExternalHostBindings() { |
780 if (!external_host_bindings_.get()) { | 828 if (!external_host_bindings_.get()) { |
781 external_host_bindings_.reset(new ExternalHostBindings( | 829 external_host_bindings_.reset(new ExternalHostBindings( |
782 render_view(), routing_id())); | 830 render_view(), routing_id())); |
783 } | 831 } |
784 return external_host_bindings_.get(); | 832 return external_host_bindings_.get(); |
785 } | 833 } |
786 | 834 |
787 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { | 835 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { |
788 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); | 836 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); |
789 } | 837 } |
OLD | NEW |