Commit 17e80a42 authored by Nico Weber's avatar Nico Weber Committed by Commit Bot

mac: Remove some uses of mac_views_browser.

Also move mac_views_browser out of declare_args so that it can no longer
be forced to false, and add a comment saying that this variable is supposed
to go away.

Bug: 832676
Change-Id: Ie2a6340715d45aa913db77595f0d578aea899ca4
Reviewed-on: https://chromium-review.googlesource.com/1209982Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589162}
parent d08cd3b8
...@@ -18,10 +18,6 @@ translated_xibs = [ ...@@ -18,10 +18,6 @@ translated_xibs = [
"Toolbar.xib", "Toolbar.xib",
] ]
if (!mac_views_browser) {
translated_xibs += [ "HttpAuthLoginSheet.xib" ]
}
untranslated_xibs = [ untranslated_xibs = [
"BookmarkBarFolderWindow.xib", "BookmarkBarFolderWindow.xib",
"FindBar.xib", "FindBar.xib",
......
This diff is collapsed.
...@@ -5099,13 +5099,6 @@ static_library("test_support") { ...@@ -5099,13 +5099,6 @@ static_library("test_support") {
deps += [ "//chromeos:test_support" ] deps += [ "//chromeos:test_support" ]
} }
if (is_mac && !mac_views_browser) {
sources += [
"chooser_controller/mock_chooser_controller.cc",
"chooser_controller/mock_chooser_controller.h",
]
}
if (is_win) { if (is_win) {
sources += [ sources += [
"notifications/win/mock_itoastnotification.cc", "notifications/win/mock_itoastnotification.cc",
......
// Copyright 2016 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.
#include "chrome/browser/chooser_controller/mock_chooser_controller.h"
#include <algorithm>
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
MockChooserController::MockChooserController()
: ChooserController(nullptr,
IDS_USB_DEVICE_CHOOSER_PROMPT_ORIGIN,
IDS_USB_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME) {
set_title_for_testing(base::ASCIIToUTF16("Mock Chooser Dialog"));
}
MockChooserController::~MockChooserController() {}
bool MockChooserController::ShouldShowIconBeforeText() const {
return true;
}
base::string16 MockChooserController::GetNoOptionsText() const {
return l10n_util::GetStringUTF16(IDS_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT);
}
base::string16 MockChooserController::GetOkButtonLabel() const {
return l10n_util::GetStringUTF16(IDS_USB_DEVICE_CHOOSER_CONNECT_BUTTON_TEXT);
}
size_t MockChooserController::NumOptions() const {
return options_.size();
}
int MockChooserController::GetSignalStrengthLevel(size_t index) const {
return options_[index].signal_strength_level;
}
base::string16 MockChooserController::GetOption(size_t index) const {
return options_[index].name;
}
bool MockChooserController::IsConnected(size_t index) const {
return options_[index].connected_paired_status &
ConnectedPairedStatus::CONNECTED;
}
bool MockChooserController::IsPaired(size_t index) const {
return options_[index].connected_paired_status &
ConnectedPairedStatus::PAIRED;
}
base::string16 MockChooserController::GetStatus() const {
return status_text_;
}
void MockChooserController::OnAdapterPresenceChanged(
content::BluetoothChooser::AdapterPresence presence) {
ClearAllOptions();
switch (presence) {
case content::BluetoothChooser::AdapterPresence::ABSENT:
NOTREACHED();
break;
case content::BluetoothChooser::AdapterPresence::POWERED_OFF:
status_text_ = base::string16();
if (view())
view()->OnAdapterEnabledChanged(false /* Adapter is turned off */);
break;
case content::BluetoothChooser::AdapterPresence::POWERED_ON:
status_text_ =
l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN);
if (view())
view()->OnAdapterEnabledChanged(true /* Adapter is turned on */);
break;
}
}
void MockChooserController::OnDiscoveryStateChanged(
content::BluetoothChooser::DiscoveryState state) {
switch (state) {
case content::BluetoothChooser::DiscoveryState::DISCOVERING:
ClearAllOptions();
status_text_ =
l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING);
if (view()) {
view()->OnRefreshStateChanged(
true /* Refreshing options is in progress */);
}
break;
case content::BluetoothChooser::DiscoveryState::IDLE:
case content::BluetoothChooser::DiscoveryState::FAILED_TO_START:
status_text_ =
l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN);
if (view()) {
view()->OnRefreshStateChanged(
false /* Refreshing options is complete */);
}
break;
}
}
void MockChooserController::OptionAdded(const base::string16& option_name,
int signal_strength_level,
int connected_paired_status) {
options_.push_back(
{option_name, signal_strength_level, connected_paired_status});
if (view())
view()->OnOptionAdded(options_.size() - 1);
}
void MockChooserController::OptionRemoved(const base::string16& option_name) {
auto it = std::find_if(options_.begin(), options_.end(),
[&option_name](const OptionInfo& option) {
return option.name == option_name;
});
if (it != options_.end()) {
size_t index = it - options_.begin();
options_.erase(it);
if (view())
view()->OnOptionRemoved(index);
}
}
void MockChooserController::OptionUpdated(
const base::string16& previous_option_name,
const base::string16& new_option_name,
int new_signal_strength_level,
int new_connected_paired_status) {
auto it = std::find_if(options_.begin(), options_.end(),
[&previous_option_name](const OptionInfo& option) {
return option.name == previous_option_name;
});
if (it != options_.end()) {
*it = {new_option_name, new_signal_strength_level,
new_connected_paired_status};
if (view())
view()->OnOptionUpdated(it - options_.begin());
}
}
const int MockChooserController::kNoSignalStrengthLevelImage = -1;
const int MockChooserController::kSignalStrengthLevel0Bar = 0;
const int MockChooserController::kSignalStrengthLevel1Bar = 1;
const int MockChooserController::kSignalStrengthLevel2Bar = 2;
const int MockChooserController::kSignalStrengthLevel3Bar = 3;
const int MockChooserController::kSignalStrengthLevel4Bar = 4;
const int MockChooserController::kImageColorUnselected = 0;
const int MockChooserController::kImageColorSelected = 1;
void MockChooserController::ClearAllOptions() {
options_.clear();
}
// Copyright 2016 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_CHOOSER_CONTROLLER_MOCK_CHOOSER_CONTROLLER_H_
#define CHROME_BROWSER_CHOOSER_CONTROLLER_MOCK_CHOOSER_CONTROLLER_H_
#include <vector>
#include "base/macros.h"
#include "chrome/browser/chooser_controller/chooser_controller.h"
#include "content/public/browser/bluetooth_chooser.h"
#include "testing/gmock/include/gmock/gmock.h"
// Deprecated. Use FakeBluetoothChooserController instead.
class MockChooserController : public ChooserController {
public:
enum ConnectedPairedStatus {
NONE = 0,
CONNECTED = 1 << 0,
PAIRED = 1 << 1,
};
MockChooserController();
~MockChooserController() override;
// ChooserController:
bool ShouldShowIconBeforeText() const override;
base::string16 GetNoOptionsText() const override;
base::string16 GetOkButtonLabel() const override;
size_t NumOptions() const override;
int GetSignalStrengthLevel(size_t index) const override;
base::string16 GetOption(size_t index) const override;
bool IsConnected(size_t index) const override;
bool IsPaired(size_t index) const override;
base::string16 GetStatus() const override;
MOCK_METHOD0(RefreshOptions, void());
MOCK_METHOD1(Select, void(const std::vector<size_t>& indices));
MOCK_METHOD0(Cancel, void());
MOCK_METHOD0(Close, void());
MOCK_CONST_METHOD0(OpenHelpCenterUrl, void());
MOCK_CONST_METHOD0(OpenAdapterOffHelpUrl, void());
void OnAdapterPresenceChanged(
content::BluetoothChooser::AdapterPresence presence);
void OnDiscoveryStateChanged(content::BluetoothChooser::DiscoveryState state);
void OptionAdded(const base::string16& option_name,
int signal_strength_level,
int connected_paired_status);
void OptionRemoved(const base::string16& option_name);
void OptionUpdated(const base::string16& previous_option_name,
const base::string16& new_option_name,
int new_signal_strengh_level,
int new_connected_paired_status);
static const int kNoSignalStrengthLevelImage;
static const int kSignalStrengthLevel0Bar;
static const int kSignalStrengthLevel1Bar;
static const int kSignalStrengthLevel2Bar;
static const int kSignalStrengthLevel3Bar;
static const int kSignalStrengthLevel4Bar;
static const int kImageColorUnselected;
static const int kImageColorSelected;
private:
void ClearAllOptions();
struct OptionInfo {
base::string16 name;
int signal_strength_level;
// This value is the '|' of ConnectedPairedStatus values.
int connected_paired_status;
};
std::vector<OptionInfo> options_;
base::string16 status_text_;
DISALLOW_COPY_AND_ASSIGN(MockChooserController);
};
#endif // CHROME_BROWSER_CHOOSER_CONTROLLER_MOCK_CHOOSER_CONTROLLER_H_
This diff is collapsed.
// 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.
#include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h"
#import <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
#include "base/macros.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_window.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_web_dialog_sheet.h"
#include "chrome/browser/ui/webui/chrome_web_contents_handler.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/base/cocoa/window_size_constants.h"
#include "ui/gfx/geometry/size.h"
#include "ui/web_dialogs/web_dialog_delegate.h"
#include "ui/web_dialogs/web_dialog_ui.h"
#include "ui/web_dialogs/web_dialog_web_contents_delegate.h"
using content::WebContents;
using ui::WebDialogDelegate;
using ui::WebDialogWebContentsDelegate;
namespace {
class ConstrainedWebDialogDelegateMac;
// This class is to trigger a resize to the dialog window when
// ResizeDueToAutoResize() is invoked.
class WebDialogWebContentsDelegateMac
: public ui::WebDialogWebContentsDelegate {
public:
WebDialogWebContentsDelegateMac(content::BrowserContext* browser_context,
content::WebContentsObserver* observer,
ConstrainedWebDialogDelegateBase* delegate)
: ui::WebDialogWebContentsDelegate(browser_context,
new ChromeWebContentsHandler()),
observer_(observer),
delegate_(delegate) {
}
~WebDialogWebContentsDelegateMac() override {}
void ResizeDueToAutoResize(content::WebContents* source,
const gfx::Size& preferred_size) override {
if (!observer_->web_contents())
return;
delegate_->ResizeToGivenSize(preferred_size);
}
private:
// These members must outlive the instance.
content::WebContentsObserver* const observer_;
ConstrainedWebDialogDelegateBase* delegate_;
DISALLOW_COPY_AND_ASSIGN(WebDialogWebContentsDelegateMac);
};
class ConstrainedWebDialogDelegateMac
: public ConstrainedWebDialogDelegateBase {
public:
ConstrainedWebDialogDelegateMac(
content::BrowserContext* browser_context,
WebDialogDelegate* delegate,
content::WebContentsObserver* observer)
: ConstrainedWebDialogDelegateBase(browser_context, delegate,
new WebDialogWebContentsDelegateMac(browser_context, observer,
this)) {}
// WebDialogWebContentsDelegate interface.
void CloseContents(WebContents* source) override {
window_->CloseWebContentsModalDialog();
}
// ConstrainedWebDialogDelegateBase:
void ResizeToGivenSize(const gfx::Size size) override {
NSSize updated_preferred_size = NSMakeSize(size.width(),
size.height());
[window_->sheet() resizeWithNewSize:updated_preferred_size];
}
void set_window(ConstrainedWindowMac* window) { window_ = window; }
ConstrainedWindowMac* window() const { return window_; }
private:
// Weak, owned by ConstrainedWebDialogDelegateViewMac.
ConstrainedWindowMac* window_;
DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateMac);
};
} // namespace
class ConstrainedWebDialogDelegateViewMac :
public ConstrainedWindowMacDelegate,
public ConstrainedWebDialogDelegate,
public content::WebContentsObserver {
public:
ConstrainedWebDialogDelegateViewMac(
content::BrowserContext* browser_context,
WebDialogDelegate* delegate,
content::WebContents* web_contents,
const gfx::Size& min_size,
const gfx::Size& max_size);
~ConstrainedWebDialogDelegateViewMac() override {}
// ConstrainedWebDialogDelegate interface
const WebDialogDelegate* GetWebDialogDelegate() const override {
return impl_->GetWebDialogDelegate();
}
WebDialogDelegate* GetWebDialogDelegate() override {
return impl_->GetWebDialogDelegate();
}
void OnDialogCloseFromWebUI() override {
return impl_->OnDialogCloseFromWebUI();
}
std::unique_ptr<content::WebContents> ReleaseWebContents() override {
return impl_->ReleaseWebContents();
}
gfx::NativeWindow GetNativeDialog() override { return window_; }
WebContents* GetWebContents() override { return impl_->GetWebContents(); }
gfx::Size GetConstrainedWebDialogMinimumSize() const override {
return min_size_;
}
gfx::Size GetConstrainedWebDialogMaximumSize() const override {
return max_size_;
}
gfx::Size GetConstrainedWebDialogPreferredSize() const override {
gfx::Size size;
if (!impl_->closed_via_webui()) {
NSRect frame = [window_ frame];
size = gfx::Size(frame.size.width, frame.size.height);
}
return size;
}
// content::WebContentsObserver:
void RenderViewCreated(content::RenderViewHost* render_view_host) override {
if (IsDialogAutoResizable())
EnableAutoResize();
}
void RenderViewHostChanged(content::RenderViewHost* old_host,
content::RenderViewHost* new_host) override {
if (IsDialogAutoResizable())
EnableAutoResize();
}
void DocumentOnLoadCompletedInMainFrame() override {
if (IsDialogAutoResizable() && GetWebContents())
constrained_window_->ShowWebContentsModalDialog();
}
// ConstrainedWindowMacDelegate interface
void OnConstrainedWindowClosed(ConstrainedWindowMac* window) override {
if (!impl_->closed_via_webui())
GetWebDialogDelegate()->OnDialogClosed("");
delete this;
}
private:
void EnableAutoResize() {
if (!GetWebContents())
return;
content::RenderViewHost* render_view_host =
GetWebContents()->GetRenderViewHost();
render_view_host->EnableAutoResize(min_size_, max_size_);
}
// Whether or not the dialog is autoresizable is determined based on whether
// |max_size_| was specified.
bool IsDialogAutoResizable() {
return !max_size_.IsEmpty();
}
std::unique_ptr<ConstrainedWebDialogDelegateMac> impl_;
std::unique_ptr<ConstrainedWindowMac> constrained_window_;
base::scoped_nsobject<NSWindow> window_;
// Minimum and maximum sizes to determine dialog bounds for auto-resizing.
const gfx::Size min_size_;
const gfx::Size max_size_;
DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewMac);
};
ConstrainedWebDialogDelegateViewMac::ConstrainedWebDialogDelegateViewMac(
content::BrowserContext* browser_context,
WebDialogDelegate* delegate,
content::WebContents* web_contents,
const gfx::Size& min_size,
const gfx::Size& max_size)
: content::WebContentsObserver(web_contents),
impl_(new ConstrainedWebDialogDelegateMac(browser_context, delegate,
this)),
min_size_(min_size),
max_size_(max_size) {
if (IsDialogAutoResizable()) {
Observe(GetWebContents());
EnableAutoResize();
}
// Create a window to hold web_contents in the constrained sheet:
gfx::Size size;
delegate->GetDialogSize(&size);
// The window size for autoresizing dialogs will be determined at a later
// time.
NSRect frame = IsDialogAutoResizable() ? ui::kWindowSizeDeterminedLater :
NSMakeRect(0, 0, size.width(), size.height());
window_.reset([[ConstrainedWindowCustomWindow alloc]
initWithContentRect:frame]);
[GetWebContents()->GetNativeView() setFrame:frame];
[GetWebContents()->GetNativeView() setAutoresizingMask:
NSViewWidthSizable|NSViewHeightSizable];
[[window_ contentView] addSubview:GetWebContents()->GetNativeView()];
base::scoped_nsobject<WebDialogConstrainedWindowSheet> sheet(
[[WebDialogConstrainedWindowSheet alloc] initWithCustomWindow:window_
webDialogDelegate:delegate]);
if (IsDialogAutoResizable()) {
constrained_window_ = CreateWebModalDialogMac(
this, web_contents, sheet);
} else {
constrained_window_ = CreateAndShowWebModalDialogMac(
this, web_contents, sheet);
}
impl_->set_window(constrained_window_.get());
}
ConstrainedWebDialogDelegate* ShowConstrainedWebDialog(
content::BrowserContext* browser_context,
WebDialogDelegate* delegate,
content::WebContents* web_contents) {
// Deleted when the dialog closes.
ConstrainedWebDialogDelegateViewMac* constrained_delegate =
new ConstrainedWebDialogDelegateViewMac(
browser_context, delegate, web_contents,
gfx::Size(), gfx::Size());
return constrained_delegate;
}
ConstrainedWebDialogDelegate* ShowConstrainedWebDialogWithAutoResize(
content::BrowserContext* browser_context,
WebDialogDelegate* delegate,
content::WebContents* web_contents,
const gfx::Size& min_size,
const gfx::Size& max_size) {
DCHECK(!min_size.IsEmpty());
DCHECK(!max_size.IsEmpty());
// Deleted when the dialog closes.
ConstrainedWebDialogDelegateViewMac* constrained_delegate =
new ConstrainedWebDialogDelegateViewMac(
browser_context, delegate, web_contents,
min_size, max_size);
return constrained_delegate;
}
// Copyright (c) 2011 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 <Cocoa/Cocoa.h>
#include "base/bind.h"
#include "base/callback.h"
#include "base/mac/scoped_nsobject.h"
#include "base/metrics/user_metrics.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/importer/importer_lock_dialog.h"
#include "chrome/browser/ui/cocoa/browser_dialogs_views_mac.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util_mac.h"
using base::UserMetricsAction;
namespace importer {
void ShowImportLockDialog(gfx::NativeWindow parent,
const base::Callback<void(bool)>& callback) {
if (chrome::ShowAllDialogsWithViewsToolkit())
return chrome::ShowImportLockDialogViews(parent, callback);
base::scoped_nsobject<NSAlert> lock_alert([[NSAlert alloc] init]);
[lock_alert addButtonWithTitle:l10n_util::GetNSStringWithFixup(
IDS_IMPORTER_LOCK_OK)];
[lock_alert addButtonWithTitle:l10n_util::GetNSStringWithFixup(IDS_CANCEL)];
[lock_alert setInformativeText:l10n_util::GetNSStringWithFixup(
IDS_IMPORTER_LOCK_TEXT)];
[lock_alert setMessageText:l10n_util::GetNSStringWithFixup(
IDS_IMPORTER_LOCK_TITLE)];
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind(callback, [lock_alert runModal] == NSAlertFirstButtonReturn));
base::RecordAction(UserMetricsAction("ImportLockDialogCocoa_Shown"));
}
} // namespace importer
// 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_LOGIN_HANDLER_COCOA_H_
#define CHROME_BROWSER_UI_COCOA_LOGIN_HANDLER_COCOA_H_
#import <Cocoa/Cocoa.h>
class LoginHandlerMac;
// Controller of the sheet used by LoginHandlerMac. Interface Builder wants
// this to be in a .h file.
@interface LoginHandlerSheet : NSWindowController {
@private
IBOutlet NSTextField* nameField_;
IBOutlet NSSecureTextField* passwordField_;
IBOutlet NSTextField* authorityField_;
IBOutlet NSTextField* explanationField_;
IBOutlet NSButton* loginButton_;
IBOutlet NSButton* cancelButton_;
LoginHandlerMac* handler_; // weak, owns us
}
- (id)initWithLoginHandler:(LoginHandlerMac*)handler;
- (IBAction)loginPressed:(id)sender;
- (IBAction)cancelPressed:(id)sender;
- (void)autofillLogin:(NSString*)login password:(NSString*)password;
- (void)setAuthority:(NSString*)authority;
- (void)setExplanation:(NSString*)explanation;
@end
#endif // CHROME_BROWSER_UI_COCOA_LOGIN_HANDLER_COCOA_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/login_handler_cocoa.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/scoped_nsobject.h"
#include "base/macros.h"
#include "base/optional.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/cocoa/browser_dialogs_views_mac.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
#include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
#include "chrome/browser/ui/login/login_handler.h"
#include "components/password_manager/core/browser/login_model.h"
#include "components/password_manager/core/browser/password_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h"
using autofill::PasswordForm;
using content::BrowserThread;
using content::WebContents;
// ----------------------------------------------------------------------------
// LoginHandlerMac
// This class simply forwards the authentication from the LoginView (on
// the UI thread) to the net::URLRequest (on the I/O thread).
// This class uses ref counting to ensure that it lives until all InvokeLaters
// have been called.
class LoginHandlerMac : public LoginHandler,
public ConstrainedWindowMacDelegate {
public:
LoginHandlerMac(
net::AuthChallengeInfo* auth_info,
content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
LoginAuthRequiredCallback auth_required_callback)
: LoginHandler(auth_info,
web_contents_getter,
std::move(auth_required_callback)) {}
// LoginModelObserver implementation.
void OnAutofillDataAvailableInternal(
const base::string16& username,
const base::string16& password) override {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
[sheet_controller_ autofillLogin:base::SysUTF16ToNSString(username)
password:base::SysUTF16ToNSString(password)];
}
void OnLoginModelDestroying() override {}
// LoginHandler:
void BuildViewImpl(const base::string16& authority,
const base::string16& explanation,
LoginModelData* login_model_data) override {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
sheet_controller_.reset(
[[LoginHandlerSheet alloc] initWithLoginHandler:this]);
if (login_model_data)
SetModel(*login_model_data);
else
ResetModel();
[sheet_controller_ setAuthority:base::SysUTF16ToNSString(authority)];
[sheet_controller_ setExplanation:base::SysUTF16ToNSString(explanation)];
// Scary thread safety note: This can potentially be called *after* SetAuth
// or CancelAuth (say, if the request was cancelled before the UI thread got
// control). However, that's OK since any UI interaction in those functions
// will occur via an InvokeLater on the UI thread, which is guaranteed
// to happen after this is called (since this was InvokeLater'd first).
WebContents* requesting_contents = GetWebContentsForLogin();
DCHECK(requesting_contents);
base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
[[CustomConstrainedWindowSheet alloc]
initWithCustomWindow:[sheet_controller_ window]]);
constrained_window_ = CreateAndShowWebModalDialogMac(
this, requesting_contents, sheet);
NotifyAuthNeeded();
}
void CloseDialog() override {
// The hosting dialog may have been freed.
if (constrained_window_)
constrained_window_->CloseWebContentsModalDialog();
}
// Overridden from ConstrainedWindowMacDelegate:
void OnConstrainedWindowClosed(ConstrainedWindowMac* window) override {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
ResetModel();
ReleaseSoon();
constrained_window_.reset();
sheet_controller_.reset();
}
void OnLoginPressed(const base::string16& username,
const base::string16& password) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
SetAuth(username, password);
}
void OnCancelPressed() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
CancelAuth();
}
private:
friend class LoginPrompt;
~LoginHandlerMac() override {
// This class will be deleted on a non UI thread. Ensure that the UI members
// have already been deleted.
CHECK(!constrained_window_.get());
CHECK(!sheet_controller_.get());
}
// The Cocoa controller of the GUI.
base::scoped_nsobject<LoginHandlerSheet> sheet_controller_;
std::unique_ptr<ConstrainedWindowMac> constrained_window_;
DISALLOW_COPY_AND_ASSIGN(LoginHandlerMac);
};
// static
scoped_refptr<LoginHandler> LoginHandler::Create(
net::AuthChallengeInfo* auth_info,
content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
LoginAuthRequiredCallback auth_required_callback) {
return chrome::CreateLoginHandlerViews(auth_info, web_contents_getter,
std::move(auth_required_callback));
}
// ----------------------------------------------------------------------------
// LoginHandlerSheet
@implementation LoginHandlerSheet
- (id)initWithLoginHandler:(LoginHandlerMac*)handler {
NSString* nibPath =
[base::mac::FrameworkBundle() pathForResource:@"HttpAuthLoginSheet"
ofType:@"nib"];
if ((self = [super initWithWindowNibPath:nibPath
owner:self])) {
handler_ = handler;
// Force the nib to load so that all outlets are initialized.
[self window];
}
return self;
}
- (void)dealloc {
// The buttons could be in a modal loop, so disconnect them so they cannot
// call back to us after we're dead.
[loginButton_ setTarget:nil];
[cancelButton_ setTarget:nil];
[super dealloc];
}
- (IBAction)loginPressed:(id)sender {
handler_->OnLoginPressed(
base::SysNSStringToUTF16([nameField_ stringValue]),
base::SysNSStringToUTF16([passwordField_ stringValue]));
}
- (IBAction)cancelPressed:(id)sender {
handler_->OnCancelPressed();
}
- (void)autofillLogin:(NSString*)login password:(NSString*)password {
if ([[nameField_ stringValue] length] == 0) {
[nameField_ setStringValue:login];
[passwordField_ setStringValue:password];
[nameField_ selectText:self];
}
}
- (void)setAuthority:(NSString*)authority {
[authorityField_ setStringValue:authority];
// Resize the text field.
CGFloat windowDelta = [GTMUILocalizerAndLayoutTweaker
sizeToFitFixedWidthTextField:authorityField_];
NSRect newFrame = [[self window] frame];
newFrame.size.height += windowDelta;
[[self window] setFrame:newFrame display:NO];
}
- (void)setExplanation:(NSString*)explanation {
[explanationField_ setStringValue:explanation];
// Resize the text field.
CGFloat windowDelta = [GTMUILocalizerAndLayoutTweaker
sizeToFitFixedWidthTextField:explanationField_];
NSRect newFrame = [[self window] frame];
newFrame.size.height += windowDelta;
[[self window] setFrame:newFrame display:NO];
}
@end
// Copyright 2017 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.
#include "base/callback.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "chrome/browser/ui/cocoa/browser_dialogs_views_mac.h"
#include "chrome/browser/ui/cocoa/simple_message_box_cocoa.h"
#include "chrome/browser/ui/simple_message_box.h"
#include "chrome/browser/ui/views/simple_message_box_views.h"
#include "ui/base/resource/resource_bundle.h"
namespace {
chrome::MessageBoxResult ShowMessageBoxImpl(
gfx::NativeWindow parent,
const base::string16& title,
const base::string16& message,
chrome::MessageBoxType type,
const base::string16& yes_text,
const base::string16& no_text,
const base::string16& checkbox_text) {
// These functions may be called early in browser startup, in which case the
// UI thread may not be ready to run or configured fully. In that case, fall
// back to native Cocoa message boxes.
if (base::MessageLoopForUI::IsCurrent() &&
base::RunLoop::IsRunningOnCurrentThread() &&
ui::ResourceBundle::HasSharedInstance() &&
chrome::ShowAllDialogsWithViewsToolkit()) {
return SimpleMessageBoxViews::Show(parent, title, message, type, yes_text,
no_text, checkbox_text);
}
// ShowMessageBoxCocoa() and NSAlerts in general don't support most of the
// above options at all.
return chrome::ShowMessageBoxCocoa(message, type, checkbox_text);
}
} // namespace
namespace chrome {
void ShowWarningMessageBox(gfx::NativeWindow parent,
const base::string16& title,
const base::string16& message) {
ShowMessageBoxImpl(parent, title, message, MESSAGE_BOX_TYPE_WARNING,
base::string16(), base::string16(), base::string16());
}
void ShowWarningMessageBoxWithCheckbox(
gfx::NativeWindow parent,
const base::string16& title,
const base::string16& message,
const base::string16& checkbox_text,
base::OnceCallback<void(bool checked)> callback) {
MessageBoxResult result =
ShowMessageBoxImpl(parent, title, message, MESSAGE_BOX_TYPE_WARNING,
base::string16(), base::string16(), checkbox_text);
std::move(callback).Run(result == MESSAGE_BOX_RESULT_YES);
}
MessageBoxResult ShowQuestionMessageBox(gfx::NativeWindow parent,
const base::string16& title,
const base::string16& message) {
return ShowMessageBoxImpl(parent, title, message, MESSAGE_BOX_TYPE_QUESTION,
base::string16(), base::string16(),
base::string16());
}
} // namespace chrome
// Copyright 2018 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.
#include "chrome/browser/ui/media_router/presentation_receiver_window.h"
#include "base/logging.h"
// static
PresentationReceiverWindow* PresentationReceiverWindow::Create(
PresentationReceiverWindowDelegate* delegate,
const gfx::Rect& bounds) {
NOTREACHED();
return nullptr;
}
...@@ -8,9 +8,6 @@ declare_args() { ...@@ -8,9 +8,6 @@ declare_args() {
# Optional system library. # Optional system library.
use_xkbcommon = false use_xkbcommon = false
# Whether the entire browser uses toolkit-views on Mac instead of Cocoa.
mac_views_browser = is_mac
# Whether the platform provides a native accessibility toolkit. # Whether the platform provides a native accessibility toolkit.
has_native_accessibility = use_atk || is_win || is_mac has_native_accessibility = use_atk || is_win || is_mac
...@@ -22,3 +19,8 @@ declare_args() { ...@@ -22,3 +19,8 @@ declare_args() {
} }
enable_hidpi = is_mac || is_win || is_linux enable_hidpi = is_mac || is_win || is_linux
# Whether the entire browser uses toolkit-views on Mac instead of Cocoa.
# TODO(https://crbug.com/832676): Now that this is always true, remove all uses
# of this and then remove it.
mac_views_browser = is_mac
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