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

Side by Side Diff: content/browser/devtools/renderer_overrides_handler.cc

Issue 23943004: Support Page.getNavigationHistory and Page.navigateToHistoryEntry in RendererOverridesHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Using unique entry id instead of index Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/devtools/renderer_overrides_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "content/browser/devtools/renderer_overrides_handler.h" 5 #include "content/browser/devtools/renderer_overrides_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "content/browser/child_process_security_policy_impl.h" 15 #include "content/browser/child_process_security_policy_impl.h"
16 #include "content/browser/devtools/devtools_protocol_constants.h" 16 #include "content/browser/devtools/devtools_protocol_constants.h"
17 #include "content/browser/devtools/devtools_tracing_handler.h" 17 #include "content/browser/devtools/devtools_tracing_handler.h"
18 #include "content/browser/renderer_host/dip_util.h" 18 #include "content/browser/renderer_host/dip_util.h"
19 #include "content/browser/renderer_host/render_view_host_delegate.h" 19 #include "content/browser/renderer_host/render_view_host_delegate.h"
20 #include "content/browser/renderer_host/render_view_host_impl.h" 20 #include "content/browser/renderer_host/render_view_host_impl.h"
21 #include "content/common/view_messages.h" 21 #include "content/common/view_messages.h"
22 #include "content/port/browser/render_widget_host_view_port.h" 22 #include "content/port/browser/render_widget_host_view_port.h"
23 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/devtools_agent_host.h" 24 #include "content/public/browser/devtools_agent_host.h"
25 #include "content/public/browser/javascript_dialog_manager.h" 25 #include "content/public/browser/javascript_dialog_manager.h"
26 #include "content/public/browser/navigation_controller.h" 26 #include "content/public/browser/navigation_controller.h"
27 #include "content/public/browser/navigation_entry.h"
27 #include "content/public/browser/render_process_host.h" 28 #include "content/public/browser/render_process_host.h"
28 #include "content/public/browser/render_view_host.h" 29 #include "content/public/browser/render_view_host.h"
29 #include "content/public/browser/render_widget_host_view.h" 30 #include "content/public/browser/render_widget_host_view.h"
30 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
31 #include "content/public/browser/web_contents_delegate.h" 32 #include "content/public/browser/web_contents_delegate.h"
32 #include "content/public/common/page_transition_types.h" 33 #include "content/public/common/page_transition_types.h"
33 #include "content/public/common/referrer.h" 34 #include "content/public/common/referrer.h"
34 #include "ipc/ipc_sender.h" 35 #include "ipc/ipc_sender.h"
35 #include "third_party/WebKit/public/web/WebInputEvent.h" 36 #include "third_party/WebKit/public/web/WebInputEvent.h"
36 #include "ui/gfx/codec/jpeg_codec.h" 37 #include "ui/gfx/codec/jpeg_codec.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 devtools::Page::handleJavaScriptDialog::kName, 90 devtools::Page::handleJavaScriptDialog::kName,
90 base::Bind( 91 base::Bind(
91 &RendererOverridesHandler::PageHandleJavaScriptDialog, 92 &RendererOverridesHandler::PageHandleJavaScriptDialog,
92 base::Unretained(this))); 93 base::Unretained(this)));
93 RegisterCommandHandler( 94 RegisterCommandHandler(
94 devtools::Page::navigate::kName, 95 devtools::Page::navigate::kName,
95 base::Bind( 96 base::Bind(
96 &RendererOverridesHandler::PageNavigate, 97 &RendererOverridesHandler::PageNavigate,
97 base::Unretained(this))); 98 base::Unretained(this)));
98 RegisterCommandHandler( 99 RegisterCommandHandler(
100 devtools::Page::getNavigationHistory::kName,
101 base::Bind(
102 &RendererOverridesHandler::PageGetNavigationHistory,
103 base::Unretained(this)));
104 RegisterCommandHandler(
105 devtools::Page::navigateToHistoryEntry::kName,
106 base::Bind(
107 &RendererOverridesHandler::PageNavigateToHistoryEntry,
108 base::Unretained(this)));
109 RegisterCommandHandler(
99 devtools::Page::captureScreenshot::kName, 110 devtools::Page::captureScreenshot::kName,
100 base::Bind( 111 base::Bind(
101 &RendererOverridesHandler::PageCaptureScreenshot, 112 &RendererOverridesHandler::PageCaptureScreenshot,
102 base::Unretained(this))); 113 base::Unretained(this)));
103 RegisterCommandHandler( 114 RegisterCommandHandler(
104 devtools::Page::startScreencast::kName, 115 devtools::Page::startScreencast::kName,
105 base::Bind( 116 base::Bind(
106 &RendererOverridesHandler::PageStartScreencast, 117 &RendererOverridesHandler::PageStartScreencast,
107 base::Unretained(this))); 118 base::Unretained(this)));
108 RegisterCommandHandler( 119 RegisterCommandHandler(
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 if (web_contents) { 304 if (web_contents) {
294 web_contents->GetController() 305 web_contents->GetController()
295 .LoadURL(gurl, Referrer(), PAGE_TRANSITION_TYPED, std::string()); 306 .LoadURL(gurl, Referrer(), PAGE_TRANSITION_TYPED, std::string());
296 return command->SuccessResponse(new base::DictionaryValue()); 307 return command->SuccessResponse(new base::DictionaryValue());
297 } 308 }
298 } 309 }
299 return command->InternalErrorResponse("No WebContents to navigate"); 310 return command->InternalErrorResponse("No WebContents to navigate");
300 } 311 }
301 312
302 scoped_refptr<DevToolsProtocol::Response> 313 scoped_refptr<DevToolsProtocol::Response>
314 RendererOverridesHandler::PageGetNavigationHistory(
315 scoped_refptr<DevToolsProtocol::Command> command) {
316 RenderViewHost* host = agent_->GetRenderViewHost();
317 if (host) {
318 WebContents* web_contents = host->GetDelegate()->GetAsWebContents();
319 if (web_contents) {
320 base::DictionaryValue* result = new base::DictionaryValue();
321 NavigationController& controller = web_contents->GetController();
322 result->SetInteger(
323 devtools::Page::getNavigationHistory::kResponseCurrentIndex,
324 controller.GetCurrentEntryIndex());
325 ListValue* entries = new ListValue();
326 for (int i = 0; i != controller.GetEntryCount(); ++i) {
327 const NavigationEntry* entry = controller.GetEntryAtIndex(i);
328 base::DictionaryValue* entry_value = new base::DictionaryValue();
329 entry_value->SetInteger(
330 devtools::Page::getNavigationHistory::kResponseEntryId,
331 entry->GetUniqueID());
332 entry_value->SetString(
333 devtools::Page::getNavigationHistory::kResponseEntryURL,
334 entry->GetURL().spec());
335 entry_value->SetString(
336 devtools::Page::getNavigationHistory::kResponseEntryTitle,
337 entry->GetTitle());
338 entries->Append(entry_value);
339 }
340 result->Set(
341 devtools::Page::getNavigationHistory::kResponseEntries,
342 entries);
343 return command->SuccessResponse(result);
344 }
345 }
346 return command->InternalErrorResponse("No WebContents to navigate");
347 }
348
349 scoped_refptr<DevToolsProtocol::Response>
350 RendererOverridesHandler::PageNavigateToHistoryEntry(
351 scoped_refptr<DevToolsProtocol::Command> command) {
352 int entry_id;
353
354 base::DictionaryValue* params = command->params();
355 const char* param = devtools::Page::navigateToHistoryEntry::kParamEntryId;
356 if (!params || !params->GetInteger(param, &entry_id)) {
357 return command->InvalidParamResponse(param);
358 }
359
360 RenderViewHost* host = agent_->GetRenderViewHost();
361 if (host) {
362 WebContents* web_contents = host->GetDelegate()->GetAsWebContents();
363 if (web_contents) {
364 NavigationController& controller = web_contents->GetController();
365 for (int i = 0; i != controller.GetEntryCount(); ++i) {
366 if (controller.GetEntryAtIndex(i)->GetUniqueID() == entry_id) {
367 controller.GoToIndex(i);
368 return command->SuccessResponse(new base::DictionaryValue());
369 }
370 }
371 return command->InternalErrorResponse("History entry not found");
pfeldman 2013/09/06 13:08:51 InvalidParameter
Vladislav Kaznacheev 2013/09/06 13:50:25 Done.
372 }
373 }
374 return command->InternalErrorResponse("No WebContents to navigate");
375 }
376
377 scoped_refptr<DevToolsProtocol::Response>
303 RendererOverridesHandler::PageCaptureScreenshot( 378 RendererOverridesHandler::PageCaptureScreenshot(
304 scoped_refptr<DevToolsProtocol::Command> command) { 379 scoped_refptr<DevToolsProtocol::Command> command) {
305 std::string format; 380 std::string format;
306 int quality = kDefaultScreenshotQuality; 381 int quality = kDefaultScreenshotQuality;
307 double scale = 1; 382 double scale = 1;
308 ParseCaptureParameters(command.get(), &format, &quality, &scale); 383 ParseCaptureParameters(command.get(), &format, &quality, &scale);
309 384
310 RenderViewHost* host = agent_->GetRenderViewHost(); 385 RenderViewHost* host = agent_->GetRenderViewHost();
311 gfx::Rect view_bounds = host->GetView()->GetViewBounds(); 386 gfx::Rect view_bounds = host->GetView()->GetViewBounds();
312 387
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 return NULL; 660 return NULL;
586 } 661 }
587 event.data.pinchUpdate.scale = static_cast<float>(scale); 662 event.data.pinchUpdate.scale = static_cast<float>(scale);
588 } 663 }
589 664
590 host->ForwardGestureEvent(event); 665 host->ForwardGestureEvent(event);
591 return command->SuccessResponse(NULL); 666 return command->SuccessResponse(NULL);
592 } 667 }
593 668
594 } // namespace content 669 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/renderer_overrides_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698