summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-05 15:01:36 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-05 15:01:36 +0000
commite3503ac87055ea7d404d0576fdb972447f3db48c (patch)
tree75071d151575dafc2f174aa756fb47bb33adc815
parent4fc2940db542dee44f8474d2eab8fdd0e814c110 (diff)
downloadchromium_src-e3503ac87055ea7d404d0576fdb972447f3db48c.zip
chromium_src-e3503ac87055ea7d404d0576fdb972447f3db48c.tar.gz
chromium_src-e3503ac87055ea7d404d0576fdb972447f3db48c.tar.bz2
Mac content shell: HTTP auth.
BUG=120526 TEST=HTTP auth works Review URL: https://chromiumcodereview.appspot.com/9980002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130918 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc2
-rw-r--r--content/content_shell.gypi6
-rw-r--r--content/public/browser/resource_dispatcher_host_login_delegate.h12
-rw-r--r--content/shell/mac/English.lproj/HttpAuth.xib350
-rw-r--r--content/shell/shell_content_browser_client.cc6
-rw-r--r--content/shell/shell_content_browser_client.h4
-rw-r--r--content/shell/shell_login_dialog.cc107
-rw-r--r--content/shell/shell_login_dialog.h87
-rw-r--r--content/shell/shell_login_dialog_mac.mm138
-rw-r--r--content/shell/shell_resource_dispatcher_host_delegate.cc35
-rw-r--r--content/shell/shell_resource_dispatcher_host_delegate.h32
11 files changed, 773 insertions, 6 deletions
diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
index 23131e2b..4da7944 100644
--- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
+++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
@@ -255,7 +255,7 @@ ResourceDispatcherHostLoginDelegate*
ChromeResourceDispatcherHostDelegate::CreateLoginDelegate(
net::AuthChallengeInfo* auth_info, net::URLRequest* request) {
std::string instant_header_value;
- // For instant, return a NULl delegate. Auth navigations don't commit the load
+ // For instant, return a NULL delegate. Auth navigations don't commit the load
// (the load remains pending) until the user cancels or succeeds in
// authorizing. Since we don't allow merging of WebContents with pending loads
// we disallow auth dialogs from showing during instant. Returning NULL does
diff --git a/content/content_shell.gypi b/content/content_shell.gypi
index d2ee56c..8e8c7be 100644
--- a/content/content_shell.gypi
+++ b/content/content_shell.gypi
@@ -84,6 +84,9 @@
'shell/shell_javascript_dialog_mac.mm',
'shell/shell_javascript_dialog_win.cc',
'shell/shell_javascript_dialog.h',
+ 'shell/shell_login_dialog_mac.mm',
+ 'shell/shell_login_dialog.cc',
+ 'shell/shell_login_dialog.h',
'shell/shell_main_delegate.cc',
'shell/shell_main_delegate.h',
'shell/shell_messages.cc',
@@ -98,6 +101,8 @@
'shell/shell_render_view_observer.h',
'shell/shell_resource_context.cc',
'shell/shell_resource_context.h',
+ 'shell/shell_resource_dispatcher_host_delegate.cc',
+ 'shell/shell_resource_dispatcher_host_delegate.h',
'shell/shell_switches.cc',
'shell/shell_switches.h',
'shell/shell_url_request_context_getter.cc',
@@ -365,6 +370,7 @@
'product_name': '<(content_shell_product_name) Framework',
'mac_bundle': 1,
'mac_bundle_resources': [
+ 'shell/mac/English.lproj/HttpAuth.xib',
'shell/mac/English.lproj/MainMenu.xib',
'<(PRODUCT_DIR)/content_shell.pak'
],
diff --git a/content/public/browser/resource_dispatcher_host_login_delegate.h b/content/public/browser/resource_dispatcher_host_login_delegate.h
index 4701240..0d99edb 100644
--- a/content/public/browser/resource_dispatcher_host_login_delegate.h
+++ b/content/public/browser/resource_dispatcher_host_login_delegate.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -12,15 +12,17 @@
namespace content {
-// Interface for getting login credentials for HTTP auth requests. When the
-// implementation has the credentials, it shoudl call the Requests's SetAuth
-// method.
+// Interface for getting login credentials for HTTP auth requests. If the
+// login delegate obtains credentials, it should call the URLRequest's SetAuth
+// method. If the user cancels, the login delegate should call the URLRequest's
+// CancelAuth instead. And in either case, it must make a call to
+// ResourceDispatcherHost::ClearLoginDelegateForRequest.
class CONTENT_EXPORT ResourceDispatcherHostLoginDelegate
: public base::RefCountedThreadSafe<ResourceDispatcherHostLoginDelegate> {
public:
virtual ~ResourceDispatcherHostLoginDelegate() {}
- // Notify the delegate that the request was cancelled.
+ // Notify the login delegate that the request was cancelled.
// This function can only be called from the IO thread.
virtual void OnRequestCancelled() = 0;
};
diff --git a/content/shell/mac/English.lproj/HttpAuth.xib b/content/shell/mac/English.lproj/HttpAuth.xib
new file mode 100644
index 0000000..2a2ac00
--- /dev/null
+++ b/content/shell/mac/English.lproj/HttpAuth.xib
@@ -0,0 +1,350 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
+ <data>
+ <int key="IBDocument.SystemTarget">1060</int>
+ <string key="IBDocument.SystemVersion">11D50b</string>
+ <string key="IBDocument.InterfaceBuilderVersion">851</string>
+ <string key="IBDocument.AppKitVersion">1138.32</string>
+ <string key="IBDocument.HIToolboxVersion">568.00</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="NS.object.0">851</string>
+ </object>
+ <object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <integer value="1"/>
+ </object>
+ <object class="NSArray" key="IBDocument.PluginDependencies">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ </object>
+ <object class="NSMutableDictionary" key="IBDocument.Metadata">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys" id="0">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSCustomObject" id="1001">
+ <string key="NSClassName">NSObject</string>
+ </object>
+ <object class="NSCustomObject" id="1003">
+ <string key="NSClassName">FirstResponder</string>
+ </object>
+ <object class="NSCustomObject" id="1004">
+ <string key="NSClassName">NSApplication</string>
+ </object>
+ <object class="NSCustomView" id="1005">
+ <reference key="NSNextResponder"/>
+ <int key="NSvFlags">268</int>
+ <object class="NSMutableArray" key="NSSubviews">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSSecureTextField" id="870871897">
+ <reference key="NSNextResponder" ref="1005"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{99, 20}, {156, 22}}</string>
+ <reference key="NSSuperview" ref="1005"/>
+ <string key="NSReuseIdentifierKey">_NS:3407</string>
+ <int key="NSTag">2</int>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSSecureTextFieldCell" key="NSCell" id="789371868">
+ <int key="NSCellFlags">343014976</int>
+ <int key="NSCellFlags2">272630848</int>
+ <string key="NSContents"/>
+ <object class="NSFont" key="NSSupport" id="749592131">
+ <string key="NSName">LucidaGrande</string>
+ <double key="NSSize">13</double>
+ <int key="NSfFlags">1040</int>
+ </object>
+ <string key="NSCellIdentifier">_NS:3407</string>
+ <reference key="NSControlView" ref="870871897"/>
+ <bool key="NSDrawsBackground">YES</bool>
+ <object class="NSColor" key="NSBackgroundColor" id="359621337">
+ <int key="NSColorSpace">6</int>
+ <string key="NSCatalogName">System</string>
+ <string key="NSColorName">textBackgroundColor</string>
+ <object class="NSColor" key="NSColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MQA</bytes>
+ </object>
+ </object>
+ <object class="NSColor" key="NSTextColor" id="1064189586">
+ <int key="NSColorSpace">6</int>
+ <string key="NSCatalogName">System</string>
+ <string key="NSColorName">textColor</string>
+ <object class="NSColor" key="NSColor" id="976070126">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MAA</bytes>
+ </object>
+ </object>
+ <object class="NSArray" key="NSAllowedInputLocales">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSAllRomanInputSourcesLocaleIdentifier</string>
+ </object>
+ </object>
+ </object>
+ <object class="NSTextField" id="249141654">
+ <reference key="NSNextResponder" ref="1005"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{99, 52}, {156, 22}}</string>
+ <reference key="NSSuperview" ref="1005"/>
+ <string key="NSReuseIdentifierKey">_NS:817</string>
+ <int key="NSTag">1</int>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="270667430">
+ <int key="NSCellFlags">-1804468671</int>
+ <int key="NSCellFlags2">272630784</int>
+ <string key="NSContents"/>
+ <reference key="NSSupport" ref="749592131"/>
+ <string key="NSCellIdentifier">_NS:817</string>
+ <reference key="NSControlView" ref="249141654"/>
+ <bool key="NSDrawsBackground">YES</bool>
+ <reference key="NSBackgroundColor" ref="359621337"/>
+ <reference key="NSTextColor" ref="1064189586"/>
+ </object>
+ </object>
+ <object class="NSTextField" id="298854538">
+ <reference key="NSNextResponder" ref="1005"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{17, 22}, {77, 17}}</string>
+ <reference key="NSSuperview" ref="1005"/>
+ <string key="NSReuseIdentifierKey">_NS:4068</string>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="212881775">
+ <int key="NSCellFlags">68288064</int>
+ <int key="NSCellFlags2">71304192</int>
+ <string key="NSContents">Password:</string>
+ <reference key="NSSupport" ref="749592131"/>
+ <string key="NSCellIdentifier">_NS:4068</string>
+ <reference key="NSControlView" ref="298854538"/>
+ <object class="NSColor" key="NSBackgroundColor" id="818604237">
+ <int key="NSColorSpace">6</int>
+ <string key="NSCatalogName">System</string>
+ <string key="NSColorName">controlColor</string>
+ <object class="NSColor" key="NSColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MC42NjY2NjY2NjY3AA</bytes>
+ </object>
+ </object>
+ <object class="NSColor" key="NSTextColor" id="1040089286">
+ <int key="NSColorSpace">6</int>
+ <string key="NSCatalogName">System</string>
+ <string key="NSColorName">controlTextColor</string>
+ <reference key="NSColor" ref="976070126"/>
+ </object>
+ </object>
+ </object>
+ <object class="NSTextField" id="881326141">
+ <reference key="NSNextResponder" ref="1005"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{17, 54}, {77, 17}}</string>
+ <reference key="NSSuperview" ref="1005"/>
+ <string key="NSReuseIdentifierKey">_NS:4068</string>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="509864529">
+ <int key="NSCellFlags">68288064</int>
+ <int key="NSCellFlags2">71304192</int>
+ <string key="NSContents">Username:</string>
+ <reference key="NSSupport" ref="749592131"/>
+ <string key="NSCellIdentifier">_NS:4068</string>
+ <reference key="NSControlView" ref="881326141"/>
+ <reference key="NSBackgroundColor" ref="818604237"/>
+ <reference key="NSTextColor" ref="1040089286"/>
+ </object>
+ </object>
+ </object>
+ <string key="NSFrameSize">{275, 94}</string>
+ <reference key="NSSuperview"/>
+ <string key="NSClassName">NSView</string>
+ </object>
+ </object>
+ <object class="IBObjectContainer" key="IBDocument.Objects">
+ <object class="NSMutableArray" key="connectionRecords">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ <object class="IBMutableOrderedSet" key="objectRecords">
+ <object class="NSArray" key="orderedObjects">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBObjectRecord">
+ <int key="objectID">0</int>
+ <reference key="object" ref="0"/>
+ <reference key="children" ref="1000"/>
+ <nil key="parent"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-2</int>
+ <reference key="object" ref="1001"/>
+ <reference key="parent" ref="0"/>
+ <string key="objectName">File's Owner</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-1</int>
+ <reference key="object" ref="1003"/>
+ <reference key="parent" ref="0"/>
+ <string key="objectName">First Responder</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-3</int>
+ <reference key="object" ref="1004"/>
+ <reference key="parent" ref="0"/>
+ <string key="objectName">Application</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">1</int>
+ <reference key="object" ref="1005"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="249141654"/>
+ <reference ref="870871897"/>
+ <reference ref="298854538"/>
+ <reference ref="881326141"/>
+ </object>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">2</int>
+ <reference key="object" ref="881326141"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="509864529"/>
+ </object>
+ <reference key="parent" ref="1005"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">3</int>
+ <reference key="object" ref="509864529"/>
+ <reference key="parent" ref="881326141"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">4</int>
+ <reference key="object" ref="298854538"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="212881775"/>
+ </object>
+ <reference key="parent" ref="1005"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">5</int>
+ <reference key="object" ref="212881775"/>
+ <reference key="parent" ref="298854538"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">6</int>
+ <reference key="object" ref="249141654"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="270667430"/>
+ </object>
+ <reference key="parent" ref="1005"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">7</int>
+ <reference key="object" ref="270667430"/>
+ <reference key="parent" ref="249141654"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">8</int>
+ <reference key="object" ref="870871897"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="789371868"/>
+ </object>
+ <reference key="parent" ref="1005"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">9</int>
+ <reference key="object" ref="789371868"/>
+ <reference key="parent" ref="870871897"/>
+ </object>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="flattenedProperties">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>-1.IBPluginDependency</string>
+ <string>-2.IBPluginDependency</string>
+ <string>-3.IBPluginDependency</string>
+ <string>1.IBEditorWindowLastContentRect</string>
+ <string>1.IBPluginDependency</string>
+ <string>1.WindowOrigin</string>
+ <string>1.editorWindowContentRectSynchronizationRect</string>
+ <string>2.IBPluginDependency</string>
+ <string>2.IBViewBoundsToFrameTransform</string>
+ <string>3.IBPluginDependency</string>
+ <string>4.IBPluginDependency</string>
+ <string>4.IBViewBoundsToFrameTransform</string>
+ <string>5.IBPluginDependency</string>
+ <string>6.IBPluginDependency</string>
+ <string>6.IBViewBoundsToFrameTransform</string>
+ <string>7.IBPluginDependency</string>
+ <string>8.IBPluginDependency</string>
+ <string>8.IBViewBoundsToFrameTransform</string>
+ <string>9.IBPluginDependency</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>{{969, 1048}, {275, 94}}</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>{628, 654}</string>
+ <string>{{357, 416}, {480, 272}}</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <object class="NSAffineTransform">
+ <bytes key="NSTransformStruct">P4AAAL+AAABBiAAAwpAAAA</bytes>
+ </object>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <object class="NSAffineTransform">
+ <bytes key="NSTransformStruct">P4AAAL+AAABBiAAAwiAAAA</bytes>
+ </object>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <object class="NSAffineTransform">
+ <bytes key="NSTransformStruct">P4AAAL+AAABCxgAAwpAAAA</bytes>
+ </object>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <object class="NSAffineTransform">
+ <bytes key="NSTransformStruct">P4AAAL+AAABCxgAAwiAAAA</bytes>
+ </object>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="unlocalizedProperties">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference key="dict.sortedKeys" ref="0"/>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <nil key="activeLocalization"/>
+ <object class="NSMutableDictionary" key="localizations">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference key="dict.sortedKeys" ref="0"/>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <nil key="sourceID"/>
+ <int key="maxID">9</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes"/>
+ <int key="IBDocument.localizationMode">0</int>
+ <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string>
+ <integer value="3000" key="NS.object.0"/>
+ </object>
+ <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
+ <nil key="IBDocument.LastKnownRelativeProjectPath"/>
+ <int key="IBDocument.defaultPropertyAccessControl">3</int>
+ </data>
+</archive>
diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc
index 588e002..cdaa0e0 100644
--- a/content/shell/shell_content_browser_client.cc
+++ b/content/shell/shell_content_browser_client.cc
@@ -6,10 +6,12 @@
#include "base/command_line.h"
#include "base/file_path.h"
+#include "content/public/browser/resource_dispatcher_host.h"
#include "content/shell/shell.h"
#include "content/shell/shell_browser_main_parts.h"
#include "content/shell/shell_devtools_delegate.h"
#include "content/shell/shell_render_view_host_observer.h"
+#include "content/shell/shell_resource_dispatcher_host_delegate.h"
#include "content/shell/shell_switches.h"
#include "googleurl/src/gurl.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -269,6 +271,10 @@ std::string ShellContentBrowserClient::GetWorkerProcessTitle(
}
void ShellContentBrowserClient::ResourceDispatcherHostCreated() {
+ resource_dispatcher_host_delegate_.reset(
+ new ShellResourceDispatcherHostDelegate());
+ ResourceDispatcherHost::Get()->SetDelegate(
+ resource_dispatcher_host_delegate_.get());
}
SpeechRecognitionManagerDelegate*
diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h
index ac5e472..67f6847 100644
--- a/content/shell/shell_content_browser_client.h
+++ b/content/shell/shell_content_browser_client.h
@@ -16,6 +16,7 @@ namespace content {
class ShellBrowserContext;
class ShellBrowserMainParts;
+class ShellResourceDispatcherHostDelegate;
class ShellContentBrowserClient : public ContentBrowserClient {
public:
@@ -189,6 +190,9 @@ class ShellContentBrowserClient : public ContentBrowserClient {
ShellBrowserContext* browser_context();
private:
+ scoped_ptr<ShellResourceDispatcherHostDelegate>
+ resource_dispatcher_host_delegate_;
+
ShellBrowserMainParts* shell_browser_main_parts_;
};
diff --git a/content/shell/shell_login_dialog.cc b/content/shell/shell_login_dialog.cc
new file mode 100644
index 0000000..def2ba3
--- /dev/null
+++ b/content/shell/shell_login_dialog.cc
@@ -0,0 +1,107 @@
+// 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 "content/shell/shell_login_dialog.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/utf_string_conversions.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/resource_dispatcher_host.h"
+#include "net/base/auth.h"
+#include "net/url_request/url_request.h"
+#include "ui/base/text/text_elider.h"
+
+namespace content {
+
+ShellLoginDialog::ShellLoginDialog(
+ net::AuthChallengeInfo* auth_info,
+ net::URLRequest* request) : auth_info_(auth_info),
+ request_(request) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&ShellLoginDialog::PrepDialog, this,
+ ASCIIToUTF16(auth_info->challenger.ToString()),
+ UTF8ToUTF16(auth_info->realm)));
+}
+
+ShellLoginDialog::~ShellLoginDialog() {
+ // Cannot post any tasks here; this object is going away and cannot be
+ // referenced/dereferenced.
+}
+
+void ShellLoginDialog::OnRequestCancelled() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&ShellLoginDialog::PlatformRequestCancelled, this));
+}
+
+void ShellLoginDialog::PrepDialog(const string16& host,
+ const string16& realm) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ // The realm is controlled by the remote server, so there is no reason to
+ // believe it is of a reasonable length.
+ string16 elided_realm;
+ ui::ElideString(realm, 120, &elided_realm);
+
+ string16 explanation =
+ ASCIIToUTF16("The server ") + host +
+ ASCIIToUTF16(" requires a username and password.");
+
+ if (!elided_realm.empty()) {
+ explanation += ASCIIToUTF16(" The server says: ");
+ explanation += elided_realm;
+ explanation += ASCIIToUTF16(".");
+ }
+
+ PlatformCreateDialog(explanation);
+}
+
+void ShellLoginDialog::UserAcceptedAuth(const string16& username,
+ const string16& password) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&ShellLoginDialog::SendAuthToRequester, this,
+ true, username, password));
+}
+
+void ShellLoginDialog::UserCancelledAuth() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&ShellLoginDialog::SendAuthToRequester, this,
+ false, string16(), string16()));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&ShellLoginDialog::PlatformCleanUp, this));
+}
+
+void ShellLoginDialog::SendAuthToRequester(bool success,
+ const string16& username,
+ const string16& password) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ if (success)
+ request_->SetAuth(net::AuthCredentials(username, password));
+ else
+ request_->CancelAuth();
+ ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(request_);
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&ShellLoginDialog::PlatformCleanUp, this));
+}
+
+#if !defined(OS_MACOSX)
+// Bogus implementations for linking. They are never called because
+// ResourceDispatcherHostDelegate::CreateLoginDelegate returns NULL.
+// TODO: implement ShellLoginDialog for other platforms, drop this #if
+void ShellLoginDialog::PlatformCreateDialog(const string16& message) {}
+void ShellLoginDialog::PlatformCleanUp() {}
+void ShellLoginDialog::PlatformRequestCancelled() {}
+#endif
+
+} // namespace content
diff --git a/content/shell/shell_login_dialog.h b/content/shell/shell_login_dialog.h
new file mode 100644
index 0000000..b944c19
--- /dev/null
+++ b/content/shell/shell_login_dialog.h
@@ -0,0 +1,87 @@
+// 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 CONTENT_SHELL_SHELL_LOGIN_DIALOG_H_
+#define CONTENT_SHELL_SHELL_LOGIN_DIALOG_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "base/string16.h"
+#include "content/public/browser/resource_dispatcher_host_login_delegate.h"
+
+#if defined(OS_MACOSX)
+#if __OBJC__
+@class ShellLoginDialogHelper;
+#else
+class ShellLoginDialogHelper;
+#endif // __OBJC__
+#endif // defined(OS_MACOSX)
+
+namespace net {
+class AuthChallengeInfo;
+class URLRequest;
+}
+
+namespace content {
+
+// This class provides a dialog box to ask the user for credentials. Useful in
+// ResourceDispatcherHostDelegate::CreateLoginDelegate.
+class ShellLoginDialog : public ResourceDispatcherHostLoginDelegate {
+ public:
+ // Threading: IO thread.
+ ShellLoginDialog(net::AuthChallengeInfo* auth_info, net::URLRequest* request);
+ // Threading: any
+ virtual ~ShellLoginDialog();
+
+ // ResourceDispatcherHostLoginDelegate implementation:
+ // Threading: IO thread.
+ virtual void OnRequestCancelled() OVERRIDE;
+
+ // Called by the platform specific code when the user responds. Public because
+ // the aforementioned platform specific code may not have access to private
+ // members. Not to be called from client code.
+ // Threading: UI thread.
+ void UserAcceptedAuth(const string16& username, const string16& password);
+ void UserCancelledAuth();
+
+ private:
+ // All the methods that begin with Platform need to be implemented by the
+ // platform specific LoginDialog implementation.
+ // Creates the dialog.
+ // Threading: UI thread.
+ void PlatformCreateDialog(const string16& message);
+ // Called from the destructor to let each platform do any necessary cleanup.
+ // Threading: UI thread.
+ void PlatformCleanUp();
+ // Called from OnRequestCancelled if the request was cancelled.
+ // Threading: UI thread.
+ void PlatformRequestCancelled();
+
+ // Sets up dialog creation.
+ // Threading: UI thread.
+ void PrepDialog(const string16& host, const string16& realm);
+
+ // Sends the authentication to the requester.
+ // Threading: IO thread.
+ void SendAuthToRequester(bool success,
+ const string16& username,
+ const string16& password);
+
+ // Who/where/what asked for the authentication.
+ // Threading: IO thread.
+ scoped_refptr<net::AuthChallengeInfo> auth_info_;
+
+ // The request that wants login data.
+ // Threading: IO thread.
+ net::URLRequest* request_;
+
+#if defined(OS_MACOSX)
+ // Threading: UI thread.
+ ShellLoginDialogHelper* helper_; // owned
+#endif
+};
+
+} // namespace content
+
+#endif // CONTENT_SHELL_SHELL_LOGIN_DIALOG_H_
diff --git a/content/shell/shell_login_dialog_mac.mm b/content/shell/shell_login_dialog_mac.mm
new file mode 100644
index 0000000..c08892d
--- /dev/null
+++ b/content/shell/shell_login_dialog_mac.mm
@@ -0,0 +1,138 @@
+// 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 "content/shell/shell_login_dialog.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/logging.h"
+#include "base/mac/bundle_locations.h"
+#import "base/mac/cocoa_protocols.h"
+#import "base/memory/scoped_nsobject.h"
+#include "base/sys_string_conversions.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace {
+
+const int kUsernameFieldTag = 1;
+const int kPasswordFieldTag = 2;
+
+} // namespace
+
+// Helper object that receives the notification that the dialog/sheet is
+// going away.
+@interface ShellLoginDialogHelper : NSObject<NSAlertDelegate> {
+ @private
+ scoped_nsobject<NSAlert> alert_;
+ NSTextField* usernameField_; // WEAK; owned by alert_
+ NSSecureTextField* passwordField_; // WEAK; owned by alert_
+}
+
+- (NSAlert*)alert;
+- (NSView*)accessoryView;
+- (void)focus;
+- (void)alertDidEnd:(NSAlert*)alert
+ returnCode:(int)returnCode
+ contextInfo:(void*)contextInfo;
+- (void)cancel;
+
+@end
+
+@implementation ShellLoginDialogHelper
+
+- (NSAlert*)alert {
+ alert_.reset([[NSAlert alloc] init]);
+ [alert_ setAccessoryView:[self accessoryView]];
+ return alert_;
+}
+
+- (NSView*)accessoryView {
+ scoped_nsobject<NSNib> nib(
+ [[NSNib alloc] initWithNibNamed:@"HttpAuth"
+ bundle:base::mac::FrameworkBundle()]);
+ if (!nib)
+ return nil;
+
+ NSArray* objects;
+ BOOL success = [nib instantiateNibWithOwner:nil
+ topLevelObjects:&objects];
+ if (!success)
+ return nil;
+ [objects makeObjectsPerformSelector:@selector(release)];
+
+ for (NSView* view in objects) {
+ if (![view isKindOfClass:[NSView class]])
+ continue;
+
+ usernameField_ = [view viewWithTag:kUsernameFieldTag];
+ passwordField_ = [view viewWithTag:kPasswordFieldTag];
+ return view;
+ }
+
+ return nil;
+}
+
+- (void)focus {
+ [[alert_ window] makeFirstResponder:usernameField_];
+}
+
+- (void)alertDidEnd:(NSAlert*)alert
+ returnCode:(int)returnCode
+ contextInfo:(void*)contextInfo {
+ if (returnCode == NSRunStoppedResponse)
+ return;
+
+ content::ShellLoginDialog* this_dialog =
+ reinterpret_cast<content::ShellLoginDialog*>(contextInfo);
+ if (returnCode == NSAlertFirstButtonReturn) {
+ this_dialog->UserAcceptedAuth(
+ base::SysNSStringToUTF16([usernameField_ stringValue]),
+ base::SysNSStringToUTF16([passwordField_ stringValue]));
+ } else {
+ this_dialog->UserCancelledAuth();
+ }
+}
+
+- (void)cancel {
+ [NSApp endSheet:[alert_ window]];
+ alert_.reset();
+}
+
+@end
+
+namespace content {
+
+void ShellLoginDialog::PlatformCreateDialog(const string16& message) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ helper_ = [[ShellLoginDialogHelper alloc] init];
+
+ // Show the modal dialog.
+ NSAlert* alert = [helper_ alert];
+ [alert setDelegate:helper_];
+ [alert setInformativeText:base::SysUTF16ToNSString(message)];
+ [alert setMessageText:@"Please log in."];
+ [alert addButtonWithTitle:@"OK"];
+ NSButton* other = [alert addButtonWithTitle:@"Cancel"];
+ [other setKeyEquivalent:@"\e"];
+ [alert
+ beginSheetModalForWindow:nil // nil here makes it app-modal
+ modalDelegate:helper_
+ didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
+ contextInfo:this];
+
+ [helper_ focus];
+}
+
+void ShellLoginDialog::PlatformCleanUp() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ [helper_ release];
+ helper_ = nil;
+}
+
+void ShellLoginDialog::PlatformRequestCancelled() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ [helper_ cancel];
+}
+
+} // namespace content
diff --git a/content/shell/shell_resource_dispatcher_host_delegate.cc b/content/shell/shell_resource_dispatcher_host_delegate.cc
new file mode 100644
index 0000000..4fc145b
--- /dev/null
+++ b/content/shell/shell_resource_dispatcher_host_delegate.cc
@@ -0,0 +1,35 @@
+// 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 "content/shell/shell_resource_dispatcher_host_delegate.h"
+
+#include "content/shell/shell_login_dialog.h"
+
+namespace content {
+
+ShellResourceDispatcherHostDelegate::ShellResourceDispatcherHostDelegate() {
+}
+
+ShellResourceDispatcherHostDelegate::~ShellResourceDispatcherHostDelegate() {
+}
+
+bool ShellResourceDispatcherHostDelegate::AcceptAuthRequest(
+ net::URLRequest* request,
+ net::AuthChallengeInfo* auth_info) {
+ // Why not give it a try?
+ return true;
+}
+
+content::ResourceDispatcherHostLoginDelegate*
+ShellResourceDispatcherHostDelegate::CreateLoginDelegate(
+ net::AuthChallengeInfo* auth_info, net::URLRequest* request) {
+#if !defined(OS_MACOSX)
+// TODO: implement ShellLoginDialog for other platforms, drop this #if
+ return NULL;
+#else
+ return new ShellLoginDialog(auth_info, request);
+#endif
+}
+
+} // namespace content
diff --git a/content/shell/shell_resource_dispatcher_host_delegate.h b/content/shell/shell_resource_dispatcher_host_delegate.h
new file mode 100644
index 0000000..ec537c5
--- /dev/null
+++ b/content/shell/shell_resource_dispatcher_host_delegate.h
@@ -0,0 +1,32 @@
+// 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 CONTENT_SHELL_SHELL_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
+#define CONTENT_SHELL_SHELL_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "content/public/browser/resource_dispatcher_host_delegate.h"
+
+namespace content {
+
+class ShellResourceDispatcherHostDelegate
+ : public content::ResourceDispatcherHostDelegate {
+ public:
+ ShellResourceDispatcherHostDelegate();
+ virtual ~ShellResourceDispatcherHostDelegate();
+
+ // ResourceDispatcherHostDelegate implementation.
+ virtual bool AcceptAuthRequest(net::URLRequest* request,
+ net::AuthChallengeInfo* auth_info) OVERRIDE;
+ virtual content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
+ net::AuthChallengeInfo* auth_info, net::URLRequest* request) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ShellResourceDispatcherHostDelegate);
+};
+
+} // namespace content
+
+#endif // CONTENT_SHELL_SHELL_RESOURCE_DISPATCHER_HOST_DELEGATE_H_