Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: chrome/renderer/chrome_render_view_observer.cc

Issue 12881005: Allow CopyFromBackingStore to fallback to copying from the renderer side if the accelerated surface… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unused include Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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)
198 IPC_MESSAGE_HANDLER(ChromeViewMsg_HandleMessageFromExternalHost, 197 IPC_MESSAGE_HANDLER(ChromeViewMsg_HandleMessageFromExternalHost,
199 OnHandleMessageFromExternalHost) 198 OnHandleMessageFromExternalHost)
200 IPC_MESSAGE_HANDLER(ChromeViewMsg_JavaScriptStressTestControl, 199 IPC_MESSAGE_HANDLER(ChromeViewMsg_JavaScriptStressTestControl,
201 OnJavaScriptStressTestControl) 200 OnJavaScriptStressTestControl)
202 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent, 201 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent,
203 OnSetAllowDisplayingInsecureContent) 202 OnSetAllowDisplayingInsecureContent)
204 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowRunningInsecureContent, 203 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowRunningInsecureContent,
205 OnSetAllowRunningInsecureContent) 204 OnSetAllowRunningInsecureContent)
206 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, 205 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection,
207 OnSetClientSidePhishingDetection) 206 OnSetClientSidePhishingDetection)
(...skipping 21 matching lines...) Expand all
229 const string16& jscript, 228 const string16& jscript,
230 int id, 229 int id,
231 bool notify_result) { 230 bool notify_result) {
232 webui_javascript_.reset(new WebUIJavaScript()); 231 webui_javascript_.reset(new WebUIJavaScript());
233 webui_javascript_->frame_xpath = frame_xpath; 232 webui_javascript_->frame_xpath = frame_xpath;
234 webui_javascript_->jscript = jscript; 233 webui_javascript_->jscript = jscript;
235 webui_javascript_->id = id; 234 webui_javascript_->id = id;
236 webui_javascript_->notify_result = notify_result; 235 webui_javascript_->notify_result = notify_result;
237 } 236 }
238 237
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
257 void ChromeRenderViewObserver::OnHandleMessageFromExternalHost( 238 void ChromeRenderViewObserver::OnHandleMessageFromExternalHost(
258 const std::string& message, 239 const std::string& message,
259 const std::string& origin, 240 const std::string& origin,
260 const std::string& target) { 241 const std::string& target) {
261 if (message.empty()) 242 if (message.empty())
262 return; 243 return;
263 GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin, 244 GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin,
264 target); 245 target);
265 } 246 }
266 247
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 // partial word indexed at the end that might have been clipped. Therefore, 769 // partial word indexed at the end that might have been clipped. Therefore,
789 // terminate the string at the last space to ensure no words are clipped. 770 // terminate the string at the last space to ensure no words are clipped.
790 if (contents->size() == kMaxIndexChars) { 771 if (contents->size() == kMaxIndexChars) {
791 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16); 772 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
792 if (last_space_index == std::wstring::npos) 773 if (last_space_index == std::wstring::npos)
793 return; // don't index if we got a huge block of text with no spaces 774 return; // don't index if we got a huge block of text with no spaces
794 contents->resize(last_space_index); 775 contents->resize(last_space_index);
795 } 776 }
796 } 777 }
797 778
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
827 ExternalHostBindings* ChromeRenderViewObserver::GetExternalHostBindings() { 779 ExternalHostBindings* ChromeRenderViewObserver::GetExternalHostBindings() {
828 if (!external_host_bindings_.get()) { 780 if (!external_host_bindings_.get()) {
829 external_host_bindings_.reset(new ExternalHostBindings( 781 external_host_bindings_.reset(new ExternalHostBindings(
830 render_view(), routing_id())); 782 render_view(), routing_id()));
831 } 783 }
832 return external_host_bindings_.get(); 784 return external_host_bindings_.get();
833 } 785 }
834 786
835 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) { 787 bool ChromeRenderViewObserver::IsStrictSecurityHost(const std::string& host) {
836 return (strict_security_hosts_.find(host) != strict_security_hosts_.end()); 788 return (strict_security_hosts_.find(host) != strict_security_hosts_.end());
837 } 789 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698