Index: content/browser/devtools/protocol/page_handler.cc |
diff --git a/content/browser/devtools/protocol/page_handler.cc b/content/browser/devtools/protocol/page_handler.cc |
index c31a27ecd24d5e9ce7fe1173af498aea53808243..28f79c0e11454d22ab3175097c99ce9e77f386a8 100644 |
--- a/content/browser/devtools/protocol/page_handler.cc |
+++ b/content/browser/devtools/protocol/page_handler.cc |
@@ -42,6 +42,7 @@ |
#include "ui/gfx/image/image.h" |
#include "ui/gfx/image/image_util.h" |
#include "ui/snapshot/snapshot.h" |
+#include "ui/views/widget/widget.h" |
#include "url/gurl.h" |
namespace content { |
@@ -594,5 +595,80 @@ Response PageHandler::StopLoading() { |
return Response::OK(); |
} |
+Response PageHandler::MaximizeWindow() { |
+ WebContentsImpl* web_contents = GetWebContents(); |
+ if (!web_contents) |
+ return Response::InternalError(); |
+ views::Widget::GetWidgetForNativeWindow( |
+ web_contents->GetTopLevelNativeWindow()) |
+ ->Maximize(); |
+ return Response::OK(); |
+} |
+ |
+Response PageHandler::MinimizeWindow() { |
+ WebContentsImpl* web_contents = GetWebContents(); |
+ if (!web_contents) |
+ return Response::InternalError(); |
+ views::Widget::GetWidgetForNativeWindow( |
+ web_contents->GetTopLevelNativeWindow()) |
+ ->Minimize(); |
+ return Response::OK(); |
+} |
+ |
+Response PageHandler::SetWindowFullscreen(Maybe<bool> fullscreen) { |
+ WebContentsImpl* web_contents = GetWebContents(); |
+ if (!web_contents) |
+ return Response::InternalError(); |
+ views::Widget::GetWidgetForNativeWindow( |
+ web_contents->GetTopLevelNativeWindow()) |
+ ->SetFullscreen(fullscreen.fromMaybe(true)); |
+ return Response::OK(); |
+} |
+ |
+Response PageHandler::SetWindowBounds(Maybe<int> left, |
+ Maybe<int> top, |
+ Maybe<int> width, |
+ Maybe<int> height) { |
+ WebContentsImpl* web_contents = GetWebContents(); |
+ if (!web_contents) |
+ return Response::InternalError(); |
+ if (width.fromMaybe(0) < 0 || height.fromMaybe(0) < 0) |
+ return Response::InvalidParams("width and height values must be positive"); |
+ 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
|
+ web_contents->GetTopLevelNativeWindow()); |
+ if (widget->IsFullscreen()) |
+ widget->SetFullscreen(false); |
+ if (widget->IsMaximized()) |
+ widget->Restore(); |
+ gfx::Rect rect = widget->GetWindowBoundsInScreen(); |
+ if (left.isJust()) |
+ rect.set_x(left.takeJust()); |
+ if (top.isJust()) |
+ rect.set_y(top.takeJust()); |
+ if (width.isJust()) |
+ rect.set_width(width.takeJust()); |
+ if (height.isJust()) |
+ rect.set_height(height.takeJust()); |
+ widget->SetBounds(rect); |
+ return Response::OK(); |
+} |
+ |
+Response PageHandler::GetWindowBounds(int* left, |
+ int* top, |
+ int* width, |
+ int* height) { |
+ WebContentsImpl* web_contents = GetWebContents(); |
+ if (!web_contents) |
+ return Response::InternalError(); |
+ auto* widget = views::Widget::GetWidgetForNativeWindow( |
+ web_contents->GetTopLevelNativeWindow()); |
+ gfx::Rect rect = widget->GetWindowBoundsInScreen(); |
+ *left = rect.x(); |
+ *top = rect.y(); |
+ *width = rect.width(); |
+ *height = rect.height(); |
+ return Response::OK(); |
+} |
+ |
} // namespace protocol |
} // namespace content |