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

Side by Side Diff: content/browser/devtools/protocol/page_handler.cc

Issue 2734123004: add a new set of commands to resize and position windows (Closed)
Patch Set: move DEPS include down to content/browser/devtools Created 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/protocol/page_handler.h" 5 #include "content/browser/devtools/protocol/page_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"
(...skipping 24 matching lines...) Expand all
35 #include "content/public/browser/web_contents_delegate.h" 35 #include "content/public/browser/web_contents_delegate.h"
36 #include "content/public/common/referrer.h" 36 #include "content/public/common/referrer.h"
37 #include "third_party/skia/include/core/SkBitmap.h" 37 #include "third_party/skia/include/core/SkBitmap.h"
38 #include "ui/base/page_transition_types.h" 38 #include "ui/base/page_transition_types.h"
39 #include "ui/gfx/codec/jpeg_codec.h" 39 #include "ui/gfx/codec/jpeg_codec.h"
40 #include "ui/gfx/codec/png_codec.h" 40 #include "ui/gfx/codec/png_codec.h"
41 #include "ui/gfx/geometry/size_conversions.h" 41 #include "ui/gfx/geometry/size_conversions.h"
42 #include "ui/gfx/image/image.h" 42 #include "ui/gfx/image/image.h"
43 #include "ui/gfx/image/image_util.h" 43 #include "ui/gfx/image/image_util.h"
44 #include "ui/snapshot/snapshot.h" 44 #include "ui/snapshot/snapshot.h"
45 #include "ui/views/widget/widget.h"
45 #include "url/gurl.h" 46 #include "url/gurl.h"
46 47
47 namespace content { 48 namespace content {
48 namespace protocol { 49 namespace protocol {
49 50
50 namespace { 51 namespace {
51 52
52 static const char kPng[] = "png"; 53 static const char kPng[] = "png";
53 static const char kJpeg[] = "jpeg"; 54 static const char kJpeg[] = "jpeg";
54 static int kDefaultScreenshotQuality = 80; 55 static int kDefaultScreenshotQuality = 80;
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 } 588 }
588 589
589 Response PageHandler::StopLoading() { 590 Response PageHandler::StopLoading() {
590 WebContentsImpl* web_contents = GetWebContents(); 591 WebContentsImpl* web_contents = GetWebContents();
591 if (!web_contents) 592 if (!web_contents)
592 return Response::InternalError(); 593 return Response::InternalError();
593 web_contents->Stop(); 594 web_contents->Stop();
594 return Response::OK(); 595 return Response::OK();
595 } 596 }
596 597
598 Response PageHandler::MaximizeWindow() {
599 WebContentsImpl* web_contents = GetWebContents();
600 if (!web_contents)
601 return Response::InternalError();
602 views::Widget::GetWidgetForNativeWindow(
603 web_contents->GetTopLevelNativeWindow())
604 ->Maximize();
605 return Response::OK();
606 }
607
608 Response PageHandler::MinimizeWindow() {
609 WebContentsImpl* web_contents = GetWebContents();
610 if (!web_contents)
611 return Response::InternalError();
612 views::Widget::GetWidgetForNativeWindow(
613 web_contents->GetTopLevelNativeWindow())
614 ->Minimize();
615 return Response::OK();
616 }
617
618 Response PageHandler::SetWindowFullscreen(Maybe<bool> fullscreen) {
619 WebContentsImpl* web_contents = GetWebContents();
620 if (!web_contents)
621 return Response::InternalError();
622 views::Widget::GetWidgetForNativeWindow(
623 web_contents->GetTopLevelNativeWindow())
624 ->SetFullscreen(fullscreen.fromMaybe(true));
625 return Response::OK();
626 }
627
628 Response PageHandler::SetWindowBounds(Maybe<int> left,
629 Maybe<int> top,
630 Maybe<int> width,
631 Maybe<int> height) {
632 WebContentsImpl* web_contents = GetWebContents();
633 if (!web_contents)
634 return Response::InternalError();
635 if (width.fromMaybe(0) < 0 || height.fromMaybe(0) < 0)
636 return Response::InvalidParams("width and height values must be positive");
637 auto* widget = views::Widget::GetWidgetForNativeWindow(
dgozman 2017/03/08 19:50:11 I believe there are not ui::views on MacOS/Android
jzfeng 2017/03/13 09:09:15 I changed to use BrowserWindow, which also works f
samuong 2017/03/13 17:23:00 From ChromeDriver's point of view, I think it's OK
638 web_contents->GetTopLevelNativeWindow());
639 if (widget->IsFullscreen())
640 widget->SetFullscreen(false);
641 if (widget->IsMaximized())
642 widget->Restore();
643 gfx::Rect rect = widget->GetWindowBoundsInScreen();
644 if (left.isJust())
645 rect.set_x(left.takeJust());
646 if (top.isJust())
647 rect.set_y(top.takeJust());
648 if (width.isJust())
649 rect.set_width(width.takeJust());
650 if (height.isJust())
651 rect.set_height(height.takeJust());
652 widget->SetBounds(rect);
653 return Response::OK();
654 }
655
656 Response PageHandler::GetWindowBounds(int* left,
657 int* top,
658 int* width,
659 int* height) {
660 WebContentsImpl* web_contents = GetWebContents();
661 if (!web_contents)
662 return Response::InternalError();
663 auto* widget = views::Widget::GetWidgetForNativeWindow(
664 web_contents->GetTopLevelNativeWindow());
665 gfx::Rect rect = widget->GetWindowBoundsInScreen();
666 *left = rect.x();
667 *top = rect.y();
668 *width = rect.width();
669 *height = rect.height();
670 return Response::OK();
671 }
672
597 } // namespace protocol 673 } // namespace protocol
598 } // namespace content 674 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698