summaryrefslogtreecommitdiffstats
path: root/ios
diff options
context:
space:
mode:
authordroger <droger@chromium.org>2015-02-23 02:25:49 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-23 10:26:36 +0000
commit25bd73e5ca8c842565f55d3a0def5036a79a7b15 (patch)
tree07ebb5c0d4c819aff7ea67154d797a036a41d454 /ios
parent9e0a7c10163c9c22adad3135a1d9fc5c3682a592 (diff)
downloadchromium_src-25bd73e5ca8c842565f55d3a0def5036a79a7b15.zip
chromium_src-25bd73e5ca8c842565f55d3a0def5036a79a7b15.tar.gz
chromium_src-25bd73e5ca8c842565f55d3a0def5036a79a7b15.tar.bz2
[iOS] Upstream chrome commands
BUG=452493 Review URL: https://codereview.chromium.org/942793002 Cr-Commit-Position: refs/heads/master@{#317558}
Diffstat (limited to 'ios')
-rw-r--r--ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h23
-rw-r--r--ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.mm24
-rw-r--r--ios/chrome/browser/ui/commands/generic_chrome_command.h23
-rw-r--r--ios/chrome/browser/ui/commands/generic_chrome_command.mm36
-rw-r--r--ios/chrome/browser/ui/commands/open_url_command.h49
-rw-r--r--ios/chrome/browser/ui/commands/open_url_command.mm76
-rw-r--r--ios/chrome/browser/ui/url_loader.h62
-rw-r--r--ios/chrome/ios_chrome.gyp7
8 files changed, 300 insertions, 0 deletions
diff --git a/ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h b/ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h
new file mode 100644
index 0000000..eed6920
--- /dev/null
+++ b/ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h
@@ -0,0 +1,23 @@
+// Copyright 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 IOS_CHROME_BROWSER_UI_UIKIT_CHROME_EXECUTE_COMMAND_H_
+#define IOS_CHROME_BROWSER_UI_UIKIT_CHROME_EXECUTE_COMMAND_H_
+
+#import <UIKit/UIKit.h>
+
+@interface UIResponder (ChromeExecuteCommand)
+// Executes a Chrome command. |sender| must implement the |-tag| method and
+// return the id of the command to execute. The default implementation of this
+// method simply forwards the call to the next responder.
+- (IBAction)chromeExecuteCommand:(id)sender;
+@end
+
+@interface UIWindow (ChromeExecuteCommand)
+// UIResponder addition to execute a Chrome command. Overridden in UIWindow to
+// forward the call to the application's delegate.
+- (void)chromeExecuteCommand:(id)sender;
+@end
+
+#endif // IOS_CHROME_BROWSER_UI_UIKIT_CHROME_EXECUTE_COMMAND_H_
diff --git a/ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.mm b/ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.mm
new file mode 100644
index 0000000..b318911
--- /dev/null
+++ b/ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.mm
@@ -0,0 +1,24 @@
+// Copyright 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 "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
+
+@implementation UIResponder (ChromeExecuteCommand)
+
+- (void)chromeExecuteCommand:(id)sender {
+ [[self nextResponder] chromeExecuteCommand:sender];
+}
+
+@end
+
+@implementation UIWindow (ChromeExecuteCommand)
+
+- (void)chromeExecuteCommand:(id)sender {
+ id delegate = [[UIApplication sharedApplication] delegate];
+
+ if ([delegate respondsToSelector:@selector(chromeExecuteCommand:)])
+ [delegate chromeExecuteCommand:sender];
+}
+
+@end
diff --git a/ios/chrome/browser/ui/commands/generic_chrome_command.h b/ios/chrome/browser/ui/commands/generic_chrome_command.h
new file mode 100644
index 0000000..7ae1c0e
--- /dev/null
+++ b/ios/chrome/browser/ui/commands/generic_chrome_command.h
@@ -0,0 +1,23 @@
+// Copyright 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 IOS_CHROME_BROWSER_UI_COMMANDS_GENERIC_CHROME_COMMAND_H_
+#define IOS_CHROME_BROWSER_UI_COMMANDS_GENERIC_CHROME_COMMAND_H_
+
+#import <Foundation/Foundation.h>
+
+// Generic command that can be passed to |chromeExecuteCommand|.
+@interface GenericChromeCommand : NSObject
+
+@property(nonatomic, assign) NSInteger tag;
+
+// Designated initializer.
+- (instancetype)initWithTag:(NSInteger)tag;
+
+// Convenience method to execute this command on the main window.
+- (void)executeOnMainWindow;
+
+@end
+
+#endif // IOS_CHROME_BROWSER_UI_COMMANDS_GENERIC_CHROME_COMMAND_H_
diff --git a/ios/chrome/browser/ui/commands/generic_chrome_command.mm b/ios/chrome/browser/ui/commands/generic_chrome_command.mm
new file mode 100644
index 0000000..bc737a6
--- /dev/null
+++ b/ios/chrome/browser/ui/commands/generic_chrome_command.mm
@@ -0,0 +1,36 @@
+// Copyright 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 "ios/chrome/browser/ui/commands/generic_chrome_command.h"
+
+#import <UIKit/UIKit.h>
+
+#include "base/logging.h"
+#import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
+
+@implementation GenericChromeCommand {
+ NSInteger _tag;
+}
+
+@synthesize tag = _tag;
+
+- (instancetype)init {
+ return [self initWithTag:0];
+}
+
+- (instancetype)initWithTag:(NSInteger)tag {
+ self = [super init];
+ if (self) {
+ _tag = tag;
+ }
+ return self;
+}
+
+- (void)executeOnMainWindow {
+ UIWindow* mainWindow = [[UIApplication sharedApplication] keyWindow];
+ DCHECK(mainWindow);
+ [mainWindow chromeExecuteCommand:self];
+}
+
+@end
diff --git a/ios/chrome/browser/ui/commands/open_url_command.h b/ios/chrome/browser/ui/commands/open_url_command.h
new file mode 100644
index 0000000..cf1f69d
--- /dev/null
+++ b/ios/chrome/browser/ui/commands/open_url_command.h
@@ -0,0 +1,49 @@
+// Copyright 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 IOS_CHROME_BROWSER_UI_COMMANDS_OPEN_URL_COMMAND_H_
+#define IOS_CHROME_BROWSER_UI_COMMANDS_OPEN_URL_COMMAND_H_
+
+#import <UIKit/UIKit.h>
+
+#import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
+#import "ios/chrome/browser/ui/url_loader.h"
+
+namespace web {
+struct Referrer;
+}
+
+class GURL;
+
+// A command to open a new tab.
+@interface OpenUrlCommand : GenericChromeCommand
+
+// Whether or not this URL command comes from a chrome context (e.g., settings),
+// as opposed to a web page context.
+@property(nonatomic, readonly) BOOL fromChrome;
+
+// Initializes a command intended to open a URL as a link from a page.
+// Designated initializer.
+- (id)initWithURL:(const GURL&)url
+ referrer:(const web::Referrer&)referrer
+ windowName:(NSString*)windowName
+ inIncognito:(BOOL)inIncognito
+ inBackground:(BOOL)inBackground
+ appendTo:(OpenPosition)append;
+
+// Initializes a command intended to open a URL from browser chrome (e.g.,
+// settings). This will always open in a new foreground tab in non-incognito
+// mode.
+- (id)initWithURLFromChrome:(const GURL&)url;
+
+- (const GURL&)url;
+- (const web::Referrer&)referrer;
+- (NSString*)windowName;
+- (BOOL)inIncognito;
+- (BOOL)inBackground;
+- (OpenPosition)appendTo;
+
+@end
+
+#endif // IOS_CHROME_BROWSER_UI_COMMANDS_OPEN_URL_COMMAND_H_
diff --git a/ios/chrome/browser/ui/commands/open_url_command.mm b/ios/chrome/browser/ui/commands/open_url_command.mm
new file mode 100644
index 0000000..a52a404
--- /dev/null
+++ b/ios/chrome/browser/ui/commands/open_url_command.mm
@@ -0,0 +1,76 @@
+// Copyright 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 "ios/chrome/browser/ui/commands/open_url_command.h"
+
+#include "base/mac/scoped_nsobject.h"
+#include "ios/web/public/referrer.h"
+#include "url/gurl.h"
+
+@implementation OpenUrlCommand {
+ GURL _url;
+ web::Referrer _referrer;
+ base::scoped_nsobject<NSString> _windowName;
+ BOOL _inIncognito;
+ BOOL _inBackground;
+ BOOL _fromChrome;
+ OpenPosition _appendTo;
+}
+
+@synthesize fromChrome = _fromChrome;
+
+- (id)initWithURL:(const GURL&)url
+ referrer:(const web::Referrer&)referrer
+ windowName:(NSString*)windowName
+ inIncognito:(BOOL)inIncognito
+ inBackground:(BOOL)inBackground
+ appendTo:(OpenPosition)appendTo {
+ if ((self = [super init])) {
+ _url = url;
+ _referrer = referrer;
+ _windowName.reset([windowName retain]);
+ _inIncognito = inIncognito;
+ _inBackground = inBackground;
+ _appendTo = appendTo;
+ }
+ return self;
+}
+
+- (id)initWithURLFromChrome:(const GURL&)url {
+ if ((self = [self initWithURL:url
+ referrer:web::Referrer()
+ windowName:nil
+ inIncognito:NO
+ inBackground:NO
+ appendTo:kLastTab])) {
+ _fromChrome = YES;
+ }
+ return self;
+}
+
+- (const GURL&)url {
+ return _url;
+}
+
+- (const web::Referrer&)referrer {
+ return _referrer;
+}
+
+- (NSString*)windowName {
+ return _windowName.get();
+}
+
+- (BOOL)inIncognito {
+ return _inIncognito;
+}
+
+- (BOOL)inBackground {
+ return _inBackground;
+}
+
+- (OpenPosition)appendTo {
+ return _appendTo;
+}
+
+@end
diff --git a/ios/chrome/browser/ui/url_loader.h b/ios/chrome/browser/ui/url_loader.h
new file mode 100644
index 0000000..88d2253
--- /dev/null
+++ b/ios/chrome/browser/ui/url_loader.h
@@ -0,0 +1,62 @@
+// Copyright 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 IOS_CHROME_BROWSER_UI_URL_LOADER_H_
+#define IOS_CHROME_BROWSER_UI_URL_LOADER_H_
+
+#import <UIKit/UIKit.h>
+
+#include "base/strings/string16.h"
+#include "ui/base/page_transition_types.h"
+
+class GURL;
+
+namespace sessions {
+struct SessionTab;
+}
+
+namespace web {
+struct Referrer;
+}
+
+// Describes the intended position for a new tab.
+enum OpenPosition {
+ kCurrentTab, // Relative to currently selected tab.
+ kLastTab // Always at end of tab model.
+};
+
+@protocol UrlLoader<NSObject>
+
+// Load a new url.
+- (void)loadURL:(const GURL&)url
+ referrer:(const web::Referrer&)referrer
+ transition:(ui::PageTransition)transition
+ rendererInitiated:(BOOL)rendererInitiated;
+
+// Load a new URL on a new page/tab. The |referrer| and |windowName| are
+// optional. The tab will be placed in the model according to |appendTo|.
+- (void)webPageOrderedOpen:(const GURL&)url
+ referrer:(const web::Referrer&)referrer
+ windowName:(NSString*)windowName
+ inBackground:(BOOL)inBackground
+ appendTo:(OpenPosition)appendTo;
+
+// Load a new URL on a new page/tab. The |referrer| and |windowName| are
+// optional. The tab will be placed in the model according to |appendTo|.
+- (void)webPageOrderedOpen:(const GURL&)url
+ referrer:(const web::Referrer&)referrer
+ windowName:(NSString*)windowName
+ inIncognito:(BOOL)inIncognito
+ inBackground:(BOOL)inBackground
+ appendTo:(OpenPosition)appendTo;
+
+// Load a tab with the given session.
+- (void)loadSessionTab:(const sessions::SessionTab*)sessionTab;
+
+// Loads the text entered in the location bar as javascript.
+- (void)loadJavaScriptFromLocationBar:(NSString*)script;
+
+@end
+
+#endif // IOS_CHROME_BROWSER_UI_URL_LOADER_H_
diff --git a/ios/chrome/ios_chrome.gyp b/ios/chrome/ios_chrome.gyp
index 284c2cc..5e68dea 100644
--- a/ios/chrome/ios_chrome.gyp
+++ b/ios/chrome/ios_chrome.gyp
@@ -101,6 +101,12 @@
'browser/translate/translate_service_ios.h',
'browser/ui/animation_util.h',
'browser/ui/animation_util.mm',
+ 'browser/ui/commands/UIKit+ChromeExecuteCommand.h',
+ 'browser/ui/commands/UIKit+ChromeExecuteCommand.mm',
+ 'browser/ui/commands/generic_chrome_command.h',
+ 'browser/ui/commands/generic_chrome_command.mm',
+ 'browser/ui/commands/open_url_command.h',
+ 'browser/ui/commands/open_url_command.mm',
'browser/ui/image_util.h',
'browser/ui/image_util.mm',
'browser/ui/reversed_animation.h',
@@ -109,6 +115,7 @@
'browser/ui/ui_util.mm',
'browser/ui/uikit_ui_util.h',
'browser/ui/uikit_ui_util.mm',
+ 'browser/ui/url_loader.h',
'browser/web/dom_altering_lock.h',
'browser/web/dom_altering_lock.mm',
'browser/web_resource/ios_web_resource_service.cc',