Commit e0eec373 authored by tapted's avatar tapted Committed by Commit bot

Mac (cleanup): Remove WebDialogs.

Nothing uses these on Mac.

They're used a lot on ChromeOS. On Windows, it shows a default browser
selection dialog. On Linux it shows the certificate viewer. On Mac I
think it was once used for a webui task manager.

BUG=None

Review URL: https://codereview.chromium.org/1640043002

Cr-Commit-Position: refs/heads/master@{#371971}
parent 17257534
......@@ -47,6 +47,11 @@ class WebDialogDelegate;
namespace chrome {
// Shows or hides the Task Manager. |browser| can be NULL when called from Ash.
void ShowTaskManager(Browser* browser);
void HideTaskManager();
#if !defined(OS_MACOSX)
// Creates and shows an HTML dialog with the given delegate and context.
// The window is automatically destroyed when it is closed.
// Returns the created window.
......@@ -57,11 +62,6 @@ gfx::NativeWindow ShowWebDialog(gfx::NativeView parent,
content::BrowserContext* context,
ui::WebDialogDelegate* delegate);
// Shows or hides the Task Manager. |browser| can be NULL when called from Ash.
void ShowTaskManager(Browser* browser);
void HideTaskManager();
#if !defined(OS_MACOSX)
// Shows the create web app shortcut dialog box.
void ShowCreateWebAppShortcutsDialog(gfx::NativeWindow parent_window,
content::WebContents* web_contents);
......
......@@ -46,7 +46,6 @@
#include "chrome/browser/ui/cocoa/status_bubble_mac.h"
#include "chrome/browser/ui/cocoa/task_manager_mac.h"
#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
#import "chrome/browser/ui/cocoa/web_dialog_window_controller.h"
#import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_controller.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
#include "chrome/browser/ui/search/search_model.h"
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_COCOA_WEB_DIALOG_WINDOW_CONTROLLER_H_
#define CHROME_BROWSER_UI_COCOA_WEB_DIALOG_WINDOW_CONTROLLER_H_
#import <Cocoa/Cocoa.h>
#include "base/memory/scoped_ptr.h"
#include "ui/web_dialogs/web_dialog_ui.h"
class WebDialogWindowDelegateBridge;
namespace content {
class BrowserContext;
class WebContents;
}
// This controller manages a dialog box with properties and HTML content taken
// from a WebDialogDelegate object.
@interface WebDialogWindowController : NSWindowController<NSWindowDelegate> {
@private
// Order here is important, as webContents_ may send messages to
// delegate_ when it gets destroyed.
scoped_ptr<WebDialogWindowDelegateBridge> delegate_;
scoped_ptr<content::WebContents> webContents_;
}
// Creates and shows an WebDialogWindowController with the given
// delegate and profile. The window is automatically destroyed when it, or its
// profile, is closed. Returns the created window.
//
// Make sure to use the returned window only when you know it is safe
// to do so, i.e. before OnDialogClosed() is called on the delegate.
+ (NSWindow*)showWebDialog:(ui::WebDialogDelegate*)delegate
context:(content::BrowserContext*)context;
@end
@interface WebDialogWindowController (TestingAPI)
// This is the designated initializer. However, this is exposed only
// for testing; use -showWebDialog:context: instead.
- (id)initWithDelegate:(ui::WebDialogDelegate*)delegate
context:(content::BrowserContext*)context;
// Loads the HTML content from the delegate; this is not a lightweight
// process which is why it is not part of the constructor. Must be
// called before -showWebDialog:context:.
- (void)loadDialogContents;
@end
#endif // CHROME_BROWSER_UI_COCOA_WEB_DIALOG_WINDOW_CONTROLLER_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/ui/cocoa/web_dialog_window_controller.h"
#include "base/logging.h"
#include "base/mac/scoped_nsobject.h"
#include "base/macros.h"
#include "base/strings/sys_string_conversions.h"
#import "chrome/browser/ui/browser_dialogs.h"
#import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
#include "chrome/browser/ui/webui/chrome_web_contents_handler.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/geometry/size.h"
#include "ui/web_dialogs/web_dialog_delegate.h"
#include "ui/web_dialogs/web_dialog_web_contents_delegate.h"
using content::NativeWebKeyboardEvent;
using content::WebContents;
using content::WebUIMessageHandler;
using ui::WebDialogDelegate;
using ui::WebDialogUI;
using ui::WebDialogWebContentsDelegate;
// Thin bridge that routes notifications to
// WebDialogWindowController's member variables.
class WebDialogWindowDelegateBridge
: public WebDialogDelegate,
public WebDialogWebContentsDelegate {
public:
// All parameters must be non-NULL/non-nil.
WebDialogWindowDelegateBridge(WebDialogWindowController* controller,
content::BrowserContext* context,
WebDialogDelegate* delegate);
~WebDialogWindowDelegateBridge() override;
// Called when the window is directly closed, e.g. from the close
// button or from an accelerator.
void WindowControllerClosed();
// WebDialogDelegate declarations.
ui::ModalType GetDialogModalType() const override;
base::string16 GetDialogTitle() const override;
GURL GetDialogContentURL() const override;
void GetWebUIMessageHandlers(
std::vector<WebUIMessageHandler*>* handlers) const override;
void GetDialogSize(gfx::Size* size) const override;
void GetMinimumDialogSize(gfx::Size* size) const override;
std::string GetDialogArgs() const override;
void OnDialogClosed(const std::string& json_retval) override;
void OnCloseContents(WebContents* source, bool* out_close_dialog) override;
bool ShouldShowDialogTitle() const override { return true; }
// WebDialogWebContentsDelegate declarations.
void MoveContents(WebContents* source, const gfx::Rect& pos) override;
void HandleKeyboardEvent(content::WebContents* source,
const NativeWebKeyboardEvent& event) override;
void CloseContents(WebContents* source) override;
content::WebContents* OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) override;
void AddNewContents(content::WebContents* source,
content::WebContents* new_contents,
WindowOpenDisposition disposition,
const gfx::Rect& initial_rect,
bool user_gesture,
bool* was_blocked) override;
void LoadingStateChanged(content::WebContents* source,
bool to_different_document) override;
private:
WebDialogWindowController* controller_; // weak
WebDialogDelegate* delegate_; // weak, owned by controller_
// Calls delegate_'s OnDialogClosed() exactly once, nulling it out afterwards
// so that no other WebDialogDelegate calls are sent to it. Returns whether or
// not the OnDialogClosed() was actually called on the delegate.
bool DelegateOnDialogClosed(const std::string& json_retval);
DISALLOW_COPY_AND_ASSIGN(WebDialogWindowDelegateBridge);
};
namespace chrome {
gfx::NativeWindow ShowWebDialog(gfx::NativeView parent,
content::BrowserContext* context,
WebDialogDelegate* delegate) {
return [WebDialogWindowController showWebDialog:delegate
context:context];
}
} // namespace chrome
WebDialogWindowDelegateBridge::WebDialogWindowDelegateBridge(
WebDialogWindowController* controller,
content::BrowserContext* context,
WebDialogDelegate* delegate)
: WebDialogWebContentsDelegate(context, new ChromeWebContentsHandler),
controller_(controller),
delegate_(delegate) {
DCHECK(controller_);
DCHECK(delegate_);
}
WebDialogWindowDelegateBridge::~WebDialogWindowDelegateBridge() {}
void WebDialogWindowDelegateBridge::WindowControllerClosed() {
Detach();
controller_ = nil;
DelegateOnDialogClosed("");
}
bool WebDialogWindowDelegateBridge::DelegateOnDialogClosed(
const std::string& json_retval) {
if (delegate_) {
WebDialogDelegate* real_delegate = delegate_;
delegate_ = NULL;
real_delegate->OnDialogClosed(json_retval);
return true;
}
return false;
}
// WebDialogDelegate definitions.
// All of these functions check for NULL first since delegate_ is set
// to NULL when the window is closed.
ui::ModalType WebDialogWindowDelegateBridge::GetDialogModalType() const {
// TODO(akalin): Support modal dialog boxes.
if (delegate_ && delegate_->GetDialogModalType() != ui::MODAL_TYPE_NONE) {
LOG(WARNING) << "Modal Web dialogs are not supported yet";
}
return ui::MODAL_TYPE_NONE;
}
base::string16 WebDialogWindowDelegateBridge::GetDialogTitle() const {
return delegate_ ? delegate_->GetDialogTitle() : base::string16();
}
GURL WebDialogWindowDelegateBridge::GetDialogContentURL() const {
return delegate_ ? delegate_->GetDialogContentURL() : GURL();
}
void WebDialogWindowDelegateBridge::GetWebUIMessageHandlers(
std::vector<WebUIMessageHandler*>* handlers) const {
if (delegate_) {
delegate_->GetWebUIMessageHandlers(handlers);
} else {
// TODO(akalin): Add this clause in the windows version. Also
// make sure that everything expects handlers to be non-NULL and
// document it.
handlers->clear();
}
}
void WebDialogWindowDelegateBridge::GetDialogSize(gfx::Size* size) const {
if (delegate_)
delegate_->GetDialogSize(size);
else
*size = gfx::Size();
}
void WebDialogWindowDelegateBridge::GetMinimumDialogSize(
gfx::Size* size) const {
if (delegate_)
delegate_->GetMinimumDialogSize(size);
else
*size = gfx::Size();
}
std::string WebDialogWindowDelegateBridge::GetDialogArgs() const {
return delegate_ ? delegate_->GetDialogArgs() : "";
}
void WebDialogWindowDelegateBridge::OnDialogClosed(
const std::string& json_retval) {
Detach();
// [controller_ close] should be called at most once, too.
if (DelegateOnDialogClosed(json_retval)) {
[controller_ close];
}
controller_ = nil;
}
void WebDialogWindowDelegateBridge::OnCloseContents(WebContents* source,
bool* out_close_dialog) {
*out_close_dialog = true;
}
void WebDialogWindowDelegateBridge::CloseContents(WebContents* source) {
bool close_dialog = false;
OnCloseContents(source, &close_dialog);
if (close_dialog)
OnDialogClosed(std::string());
}
content::WebContents* WebDialogWindowDelegateBridge::OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) {
content::WebContents* new_contents = NULL;
if (delegate_ &&
delegate_->HandleOpenURLFromTab(source, params, &new_contents)) {
return new_contents;
}
return WebDialogWebContentsDelegate::OpenURLFromTab(source, params);
}
void WebDialogWindowDelegateBridge::AddNewContents(
content::WebContents* source,
content::WebContents* new_contents,
WindowOpenDisposition disposition,
const gfx::Rect& initial_rect,
bool user_gesture,
bool* was_blocked) {
if (delegate_ && delegate_->HandleAddNewContents(
source, new_contents, disposition, initial_rect, user_gesture)) {
return;
}
WebDialogWebContentsDelegate::AddNewContents(
source, new_contents, disposition, initial_rect, user_gesture,
was_blocked);
}
void WebDialogWindowDelegateBridge::LoadingStateChanged(
content::WebContents* source, bool to_different_document) {
if (delegate_)
delegate_->OnLoadingStateChanged(source);
}
void WebDialogWindowDelegateBridge::MoveContents(WebContents* source,
const gfx::Rect& pos) {
// TODO(akalin): Actually set the window bounds.
}
// A simplified version of BrowserWindowCocoa::HandleKeyboardEvent().
// We don't handle global keyboard shortcuts here, but that's fine since
// they're all browser-specific. (This may change in the future.)
void WebDialogWindowDelegateBridge::HandleKeyboardEvent(
content::WebContents* source,
const NativeWebKeyboardEvent& event) {
if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char)
return;
// Close ourselves if the user hits Esc or Command-. . The normal
// way to do this is to implement (void)cancel:(int)sender, but
// since we handle keyboard events ourselves we can't do that.
//
// According to experiments, hitting Esc works regardless of the
// presence of other modifiers (as long as it's not an app-level
// shortcut, e.g. Commmand-Esc for Front Row) but no other modifiers
// can be present for Command-. to work.
//
// TODO(thakis): It would be nice to get cancel: to work somehow.
// Bug: http://code.google.com/p/chromium/issues/detail?id=32828 .
if (event.type == NativeWebKeyboardEvent::RawKeyDown &&
((event.windowsKeyCode == ui::VKEY_ESCAPE) ||
(event.windowsKeyCode == ui::VKEY_OEM_PERIOD &&
event.modifiers == NativeWebKeyboardEvent::MetaKey))) {
[controller_ close];
return;
}
ChromeEventProcessingWindow* event_window =
static_cast<ChromeEventProcessingWindow*>([controller_ window]);
DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]);
[event_window redispatchKeyEvent:event.os_event];
}
@implementation WebDialogWindowController
// NOTE(akalin): We'll probably have to add the parentWindow parameter back
// in once we implement modal dialogs.
+ (NSWindow*)showWebDialog:(WebDialogDelegate*)delegate
context:(content::BrowserContext*)context {
WebDialogWindowController* webDialogWindowController =
[[WebDialogWindowController alloc] initWithDelegate:delegate
context:context];
[webDialogWindowController loadDialogContents];
[webDialogWindowController showWindow:nil];
return [webDialogWindowController window];
}
- (id)initWithDelegate:(WebDialogDelegate*)delegate
context:(content::BrowserContext*)context {
DCHECK(delegate);
DCHECK(context);
gfx::Size dialogSize;
delegate->GetDialogSize(&dialogSize);
NSRect dialogRect = NSMakeRect(0, 0, dialogSize.width(), dialogSize.height());
NSUInteger style = NSTitledWindowMask | NSClosableWindowMask |
NSResizableWindowMask;
base::scoped_nsobject<ChromeEventProcessingWindow> window(
[[ChromeEventProcessingWindow alloc]
initWithContentRect:dialogRect
styleMask:style
backing:NSBackingStoreBuffered
defer:NO]);
if (!window.get()) {
return nil;
}
self = [super initWithWindow:window];
if (!self) {
return nil;
}
[window setWindowController:self];
[window setDelegate:self];
[window setTitle:base::SysUTF16ToNSString(delegate->GetDialogTitle())];
[window setMinSize:dialogRect.size];
[window center];
delegate_.reset(
new WebDialogWindowDelegateBridge(self, context, delegate));
return self;
}
- (void)loadDialogContents {
webContents_.reset(WebContents::Create(
WebContents::CreateParams(delegate_->browser_context())));
[[self window] setContentView:webContents_->GetNativeView()];
webContents_->SetDelegate(delegate_.get());
// This must be done before loading the page; see the comments in
// WebDialogUI.
WebDialogUI::SetDelegate(webContents_.get(), delegate_.get());
webContents_->GetController().LoadURL(
delegate_->GetDialogContentURL(),
content::Referrer(),
ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
std::string());
// TODO(akalin): add accelerator for ESC to close the dialog box.
//
// TODO(akalin): Figure out why implementing (void)cancel:(id)sender
// to do the above doesn't work.
}
- (void)windowWillClose:(NSNotification*)notification {
delegate_->WindowControllerClosed();
[self autorelease];
}
@end
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/ui/cocoa/web_dialog_window_controller.h"
#include <string>
#include <vector>
#import <Cocoa/Cocoa.h>
#import "base/mac/scoped_nsautorelease_pool.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"
#include "ui/web_dialogs/web_dialog_delegate.h"
#include "url/gurl.h"
using content::WebContents;
using content::WebUIMessageHandler;
using ui::WebDialogDelegate;
namespace {
class MockDelegate : public WebDialogDelegate {
public:
MOCK_CONST_METHOD0(GetDialogModalType, ui::ModalType());
MOCK_CONST_METHOD0(GetDialogTitle, base::string16());
MOCK_CONST_METHOD0(GetDialogContentURL, GURL());
MOCK_CONST_METHOD1(GetWebUIMessageHandlers,
void(std::vector<WebUIMessageHandler*>*));
MOCK_CONST_METHOD1(GetDialogSize, void(gfx::Size*));
MOCK_CONST_METHOD0(GetDialogArgs, std::string());
MOCK_METHOD1(OnDialogClosed, void(const std::string& json_retval));
MOCK_METHOD2(OnCloseContents,
void(WebContents* source, bool* out_close_dialog));
MOCK_CONST_METHOD0(ShouldShowDialogTitle, bool());
};
class WebDialogWindowControllerTest : public BrowserWithTestWindowTest {
public:
void SetUp() override {
BrowserWithTestWindowTest::SetUp();
CocoaTest::BootstrapCocoa();
title_ = base::ASCIIToUTF16("Mock Title");
size_ = gfx::Size(50, 100);
gurl_ = GURL("");
}
protected:
base::string16 title_;
gfx::Size size_;
GURL gurl_;
// Order here is important.
MockDelegate delegate_;
};
using ::testing::_;
using ::testing::Return;
using ::testing::SetArgumentPointee;
// TODO(akalin): We can't test much more than the below without a real browser.
// In particular, GetWebUIMessageHandlers() and GetDialogArgs() are never
// called. This should be fixed.
TEST_F(WebDialogWindowControllerTest, showDialog) {
// We want to make sure web_dialog_window_controller below gets
// destroyed before delegate_, so we specify our own autorelease pool.
//
// TODO(dmaclach): Remove this once
// http://code.google.com/p/chromium/issues/detail?id=26133 is fixed.
base::mac::ScopedNSAutoreleasePool release_pool;
EXPECT_CALL(delegate_, GetDialogTitle())
.WillOnce(Return(title_));
EXPECT_CALL(delegate_, GetDialogSize(_))
.WillOnce(SetArgumentPointee<0>(size_));
EXPECT_CALL(delegate_, GetDialogContentURL())
.WillOnce(Return(gurl_));
EXPECT_CALL(delegate_, OnDialogClosed(_))
.Times(1);
WebDialogWindowController* web_dialog_window_controller =
[[WebDialogWindowController alloc] initWithDelegate:&delegate_
context:profile()];
[web_dialog_window_controller loadDialogContents];
[web_dialog_window_controller showWindow:nil];
[web_dialog_window_controller close];
}
} // namespace
......@@ -1283,8 +1283,6 @@
'browser/ui/cocoa/view_resizer.h',
'browser/ui/cocoa/web_contents_modal_dialog_manager_views_mac.h',
'browser/ui/cocoa/web_contents_modal_dialog_manager_views_mac.mm',
'browser/ui/cocoa/web_dialog_window_controller.h',
'browser/ui/cocoa/web_dialog_window_controller.mm',
'browser/ui/cocoa/website_settings/chooser_bubble_ui_cocoa.h',
'browser/ui/cocoa/website_settings/chooser_bubble_ui_cocoa.mm',
'browser/ui/cocoa/website_settings/permission_bubble_cocoa.h',
......
......@@ -1339,7 +1339,6 @@
'browser/ui/cocoa/vertical_gradient_view_unittest.mm',
'browser/ui/cocoa/view_resizer_pong.h',
'browser/ui/cocoa/view_resizer_pong.mm',
'browser/ui/cocoa/web_dialog_window_controller_unittest.mm',
'browser/ui/cocoa/website_settings/permission_bubble_controller_unittest.mm',
'browser/ui/cocoa/website_settings/permission_selector_button_unittest.mm',
'browser/ui/cocoa/website_settings/website_settings_bubble_controller_unittest.mm',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment