summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/applescript
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-01 16:34:49 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-01 16:34:49 +0000
commit7d791652c7ede4209a2014d885148e2713f49bce (patch)
treec26baf12593bed381c631b81c736106809d46b44 /chrome/browser/cocoa/applescript
parent3b94427c99bdf12836fd455eeb1499fdde511e26 (diff)
downloadchromium_src-7d791652c7ede4209a2014d885148e2713f49bce.zip
chromium_src-7d791652c7ede4209a2014d885148e2713f49bce.tar.gz
chromium_src-7d791652c7ede4209a2014d885148e2713f49bce.tar.bz2
Move browser/cocoa to browser/ui/cocoa
BUG=none TEST=none TBR=brettw git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67854 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/applescript')
-rw-r--r--chrome/browser/cocoa/applescript/bookmark_applescript_utils_unittest.h53
-rw-r--r--chrome/browser/cocoa/applescript/bookmark_applescript_utils_unittest.mm62
-rw-r--r--chrome/browser/cocoa/applescript/bookmark_folder_applescript.h70
-rw-r--r--chrome/browser/cocoa/applescript/bookmark_folder_applescript.mm204
-rw-r--r--chrome/browser/cocoa/applescript/bookmark_folder_applescript_unittest.mm200
-rw-r--r--chrome/browser/cocoa/applescript/bookmark_item_applescript.h33
-rw-r--r--chrome/browser/cocoa/applescript/bookmark_item_applescript.mm66
-rw-r--r--chrome/browser/cocoa/applescript/bookmark_item_applescript_unittest.mm45
-rw-r--r--chrome/browser/cocoa/applescript/bookmark_node_applescript.h48
-rw-r--r--chrome/browser/cocoa/applescript/bookmark_node_applescript.mm130
-rw-r--r--chrome/browser/cocoa/applescript/browsercrapplication+applescript.h59
-rw-r--r--chrome/browser/cocoa/applescript/browsercrapplication+applescript.mm136
-rw-r--r--chrome/browser/cocoa/applescript/browsercrapplication+applescript_test.mm107
-rw-r--r--chrome/browser/cocoa/applescript/constants_applescript.h31
-rw-r--r--chrome/browser/cocoa/applescript/constants_applescript.mm25
-rw-r--r--chrome/browser/cocoa/applescript/element_applescript.h37
-rw-r--r--chrome/browser/cocoa/applescript/element_applescript.mm38
-rw-r--r--chrome/browser/cocoa/applescript/error_applescript.h41
-rw-r--r--chrome/browser/cocoa/applescript/error_applescript.mm56
-rw-r--r--chrome/browser/cocoa/applescript/examples/advanced_tab_manipulation.applescript24
-rw-r--r--chrome/browser/cocoa/applescript/examples/app_info.applescript9
-rw-r--r--chrome/browser/cocoa/applescript/examples/bookmark_current_tabs.applescript23
-rw-r--r--chrome/browser/cocoa/applescript/examples/copy_html.applescript16
-rw-r--r--chrome/browser/cocoa/applescript/examples/delete_bookmarks.applescript13
-rw-r--r--chrome/browser/cocoa/applescript/examples/execute_javascript.applescript10
-rw-r--r--chrome/browser/cocoa/applescript/examples/open_tabs_from_bookmark_folder.applescript12
-rw-r--r--chrome/browser/cocoa/applescript/examples/quit_app.applescript8
-rw-r--r--chrome/browser/cocoa/applescript/examples/tab_manipulation.applescript45
-rw-r--r--chrome/browser/cocoa/applescript/examples/tab_navigation.applescript13
-rw-r--r--chrome/browser/cocoa/applescript/examples/window_creation.applescript10
-rw-r--r--chrome/browser/cocoa/applescript/examples/window_operations.applescript22
-rw-r--r--chrome/browser/cocoa/applescript/scripting.sdef304
-rw-r--r--chrome/browser/cocoa/applescript/tab_applescript.h79
-rw-r--r--chrome/browser/cocoa/applescript/tab_applescript.mm296
-rw-r--r--chrome/browser/cocoa/applescript/window_applescript.h81
-rw-r--r--chrome/browser/cocoa/applescript/window_applescript.mm246
-rw-r--r--chrome/browser/cocoa/applescript/window_applescript_test.mm178
37 files changed, 0 insertions, 2830 deletions
diff --git a/chrome/browser/cocoa/applescript/bookmark_applescript_utils_unittest.h b/chrome/browser/cocoa/applescript/bookmark_applescript_utils_unittest.h
deleted file mode 100644
index bb77726..0000000
--- a/chrome/browser/cocoa/applescript/bookmark_applescript_utils_unittest.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (c) 2010 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_COCOA_APPLESCRIPT_BOOKMARK_APPLESCRIPT_UTILS_UNITTEST_H_
-#define CHROME_BROWSER_COCOA_APPLESCRIPT_BOOKMARK_APPLESCRIPT_UTILS_UNITTEST_H_
-
-#import <objc/objc-runtime.h>
-#import <Cocoa/Cocoa.h>
-
-#include "base/scoped_nsobject.h"
-#import "chrome/browser/app_controller_mac.h"
-#import "chrome/browser/cocoa/applescript/bookmark_folder_applescript.h"
-#include "chrome/browser/cocoa/browser_test_helper.h"
-#include "chrome/browser/cocoa/cocoa_test_helper.h"
-#include "chrome/test/model_test_utils.h"
-#include "testing/platform_test.h"
-
-class BookmarkModel;
-
-// The fake object that acts as our app's delegate, useful for testing purposes.
-@interface FakeAppDelegate : AppController {
- @public
- BrowserTestHelper* helper_; // weak.
-}
-@property (nonatomic) BrowserTestHelper* helper;
-// Return the |TestingProfile*| which is used for testing.
-- (Profile*)defaultProfile;
-@end
-
-
-// Used to emulate an active running script, useful for testing purposes.
-@interface FakeScriptCommand : NSScriptCommand {
- Method originalMethod_;
- Method alternateMethod_;
-}
-@end
-
-
-// The base class for all our bookmark releated unit tests.
-class BookmarkAppleScriptTest : public CocoaTest {
- public:
- BookmarkAppleScriptTest();
- private:
- BrowserTestHelper helper_;
- scoped_nsobject<FakeAppDelegate> appDelegate_;
- protected:
- scoped_nsobject<BookmarkFolderAppleScript> bookmarkBar_;
- BookmarkModel& model();
-};
-
-#endif
-// CHROME_BROWSER_COCOA_APPLESCRIPT_BOOKMARK_APPLESCRIPT_UTILS_UNITTEST_H_
diff --git a/chrome/browser/cocoa/applescript/bookmark_applescript_utils_unittest.mm b/chrome/browser/cocoa/applescript/bookmark_applescript_utils_unittest.mm
deleted file mode 100644
index bea8970..0000000
--- a/chrome/browser/cocoa/applescript/bookmark_applescript_utils_unittest.mm
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright (c) 2010 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/cocoa/applescript/bookmark_applescript_utils_unittest.h"
-
-#include "chrome/browser/bookmarks/bookmark_model.h"
-
-@implementation FakeAppDelegate
-
-@synthesize helper = helper_;
-
-- (Profile*)defaultProfile {
- if (!helper_)
- return NULL;
- return helper_->profile();
-}
-@end
-
-// Represents the current fake command that is executing.
-static FakeScriptCommand* kFakeCurrentCommand;
-
-@implementation FakeScriptCommand
-
-- (id)init {
- if ((self = [super init])) {
- originalMethod_ = class_getClassMethod([NSScriptCommand class],
- @selector(currentCommand));
- alternateMethod_ = class_getClassMethod([self class],
- @selector(currentCommand));
- method_exchangeImplementations(originalMethod_, alternateMethod_);
- kFakeCurrentCommand = self;
- }
- return self;
-}
-
-+ (NSScriptCommand*)currentCommand {
- return kFakeCurrentCommand;
-}
-
-- (void)dealloc {
- method_exchangeImplementations(originalMethod_, alternateMethod_);
- kFakeCurrentCommand = nil;
- [super dealloc];
-}
-
-@end
-
-BookmarkAppleScriptTest::BookmarkAppleScriptTest() {
- appDelegate_.reset([[FakeAppDelegate alloc] init]);
- [appDelegate_.get() setHelper:&helper_];
- [NSApp setDelegate:appDelegate_];
- const BookmarkNode* root = model().GetBookmarkBarNode();
- const std::string modelString("a f1:[ b d c ] d f2:[ e f g ] h ");
- model_test_utils::AddNodesFromModelString(model(), root, modelString);
- bookmarkBar_.reset([[BookmarkFolderAppleScript alloc]
- initWithBookmarkNode:model().GetBookmarkBarNode()]);
-}
-
-BookmarkModel& BookmarkAppleScriptTest::model() {
- return *helper_.profile()->GetBookmarkModel();
-}
diff --git a/chrome/browser/cocoa/applescript/bookmark_folder_applescript.h b/chrome/browser/cocoa/applescript/bookmark_folder_applescript.h
deleted file mode 100644
index f56a3f9..0000000
--- a/chrome/browser/cocoa/applescript/bookmark_folder_applescript.h
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright (c) 2010 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_COCOA_APPLESCRIPT_BOOKMARK_FOLDER_APPLESCRIPT_H_
-#define CHROME_BROWSER_COCOA_APPLESCRIPT_BOOKMARK_FOLDER_APPLESCRIPT_H_
-
-#import <Cocoa/Cocoa.h>
-
-#import "chrome/browser/cocoa/applescript/bookmark_node_applescript.h"
-
-@class BookmarkItemAppleScript;
-
-// Represent a bookmark folder scriptable object in applescript.
-@interface BookmarkFolderAppleScript : BookmarkNodeAppleScript {
-
-}
-
-// Bookmark folder manipulation methods.
-// Returns an array of |BookmarkFolderAppleScript*| of all the bookmark folders
-// contained within this particular folder.
-- (NSArray*)bookmarkFolders;
-
-// Inserts a bookmark folder at the end.
-- (void)insertInBookmarkFolders:(id)aBookmarkFolder;
-
-// Inserts a bookmark folder at some position in the list.
-// Called by applescript which takes care of bounds checking, make sure of it
-// before calling directly.
-- (void)insertInBookmarkFolders:(id)aBookmarkFolder atIndex:(int)index;
-
-// Remove a bookmark folder from the list.
-// Called by applescript which takes care of bounds checking, make sure of it
-// before calling directly.
-- (void)removeFromBookmarkFoldersAtIndex:(int)index;
-
-// Bookmark item manipulation methods.
-// Returns an array of |BookmarkItemAppleScript*| of all the bookmark items
-// contained within this particular folder.
-- (NSArray*)bookmarkItems;
-
-// Inserts a bookmark item at the end.
-- (void)insertInBookmarkItems:(BookmarkItemAppleScript*)aBookmarkItem;
-
-// Inserts a bookmark item at some position in the list.
-// Called by applescript which takes care of bounds checking, make sure of it
-// before calling directly.
-- (void)insertInBookmarkItems:(BookmarkItemAppleScript*)aBookmarkItem
- atIndex:(int)index;
-
-// Removes a bookmarks folder from the list.
-// Called by applescript which takes care of bounds checking, make sure of it
-// before calling directly.
-- (void)removeFromBookmarkItemsAtIndex:(int)index;
-
-// Returns the position of a bookmark folder within the current bookmark folder
-// which consists of bookmark folders as well as bookmark items.
-// AppleScript makes sure that there is a bookmark folder before calling this
-// method, make sure of that before calling directly.
-- (int)calculatePositionOfBookmarkFolderAt:(int)index;
-
-// Returns the position of a bookmark item within the current bookmark folder
-// which consists of bookmark folders as well as bookmark items.
-// AppleScript makes sure that there is a bookmark item before calling this
-// method, make sure of that before calling directly.
-- (int)calculatePositionOfBookmarkItemAt:(int)index;
-
-@end
-
-#endif // CHROME_BROWSER_COCOA_APPLESCRIPT_BOOKMARK_FOLDER_APPLESCRIPT_H_
diff --git a/chrome/browser/cocoa/applescript/bookmark_folder_applescript.mm b/chrome/browser/cocoa/applescript/bookmark_folder_applescript.mm
deleted file mode 100644
index 203a954..0000000
--- a/chrome/browser/cocoa/applescript/bookmark_folder_applescript.mm
+++ /dev/null
@@ -1,204 +0,0 @@
-// Copyright (c) 2010 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/cocoa/applescript/bookmark_folder_applescript.h"
-
-#import "base/scoped_nsobject.h"
-#import "base/string16.h"
-#include "base/sys_string_conversions.h"
-#include "chrome/browser/bookmarks/bookmark_model.h"
-#import "chrome/browser/cocoa/applescript/bookmark_item_applescript.h"
-#import "chrome/browser/cocoa/applescript/constants_applescript.h"
-#include "chrome/browser/cocoa/applescript/error_applescript.h"
-#include "googleurl/src/gurl.h"
-
-@implementation BookmarkFolderAppleScript
-
-- (NSArray*)bookmarkFolders {
- NSMutableArray* bookmarkFolders = [NSMutableArray
- arrayWithCapacity:bookmarkNode_->GetChildCount()];
-
- for (int i = 0; i < bookmarkNode_->GetChildCount(); ++i) {
- const BookmarkNode* node = bookmarkNode_->GetChild(i);
-
- if (!node->is_folder())
- continue;
- scoped_nsobject<BookmarkFolderAppleScript> bookmarkFolder(
- [[BookmarkFolderAppleScript alloc]
- initWithBookmarkNode:node]);
- [bookmarkFolder setContainer:self
- property:AppleScript::kBookmarkFoldersProperty];
- [bookmarkFolders addObject:bookmarkFolder];
- }
-
- return bookmarkFolders;
-}
-
-- (void)insertInBookmarkFolders:(id)aBookmarkFolder {
- // This method gets called when a new bookmark folder is created so
- // the container and property are set here.
- [aBookmarkFolder setContainer:self
- property:AppleScript::kBookmarkFoldersProperty];
- BookmarkModel* model = [self bookmarkModel];
- if (!model)
- return;
-
- const BookmarkNode* node = model->AddGroup(bookmarkNode_,
- bookmarkNode_->GetChildCount(),
- string16());
- if (!node) {
- AppleScript::SetError(AppleScript::errCreateBookmarkFolder);
- return;
- }
-
- [aBookmarkFolder setBookmarkNode:node];
-}
-
-- (void)insertInBookmarkFolders:(id)aBookmarkFolder atIndex:(int)index {
- // This method gets called when a new bookmark folder is created so
- // the container and property are set here.
- [aBookmarkFolder setContainer:self
- property:AppleScript::kBookmarkFoldersProperty];
- int position = [self calculatePositionOfBookmarkFolderAt:index];
-
- BookmarkModel* model = [self bookmarkModel];
- if (!model)
- return;
-
- const BookmarkNode* node = model->AddGroup(bookmarkNode_,
- position,
- string16());
- if (!node) {
- AppleScript::SetError(AppleScript::errCreateBookmarkFolder);
- return;
- }
-
- [aBookmarkFolder setBookmarkNode:node];
-}
-
-- (void)removeFromBookmarkFoldersAtIndex:(int)index {
- int position = [self calculatePositionOfBookmarkFolderAt:index];
-
- BookmarkModel* model = [self bookmarkModel];
- if (!model)
- return;
-
- model->Remove(bookmarkNode_, position);
-}
-
-- (NSArray*)bookmarkItems {
- NSMutableArray* bookmarkItems = [NSMutableArray
- arrayWithCapacity:bookmarkNode_->GetChildCount()];
-
- for (int i = 0; i < bookmarkNode_->GetChildCount(); ++i) {
- const BookmarkNode* node = bookmarkNode_->GetChild(i);
-
- if (!node->is_url())
- continue;
- scoped_nsobject<BookmarkFolderAppleScript> bookmarkItem(
- [[BookmarkItemAppleScript alloc]
- initWithBookmarkNode:node]);
- [bookmarkItem setContainer:self
- property:AppleScript::kBookmarkItemsProperty];
- [bookmarkItems addObject:bookmarkItem];
- }
-
- return bookmarkItems;
-}
-
-- (void)insertInBookmarkItems:(BookmarkItemAppleScript*)aBookmarkItem {
- // This method gets called when a new bookmark item is created so
- // the container and property are set here.
- [aBookmarkItem setContainer:self
- property:AppleScript::kBookmarkItemsProperty];
-
- BookmarkModel* model = [self bookmarkModel];
- if (!model)
- return;
-
- GURL url = GURL(base::SysNSStringToUTF8([aBookmarkItem URL]));
- if (!url.is_valid()) {
- AppleScript::SetError(AppleScript::errInvalidURL);
- return;
- }
-
- const BookmarkNode* node = model->AddURL(bookmarkNode_,
- bookmarkNode_->GetChildCount(),
- string16(),
- url);
- if (!node) {
- AppleScript::SetError(AppleScript::errCreateBookmarkItem);
- return;
- }
-
- [aBookmarkItem setBookmarkNode:node];
-}
-
-- (void)insertInBookmarkItems:(BookmarkItemAppleScript*)aBookmarkItem
- atIndex:(int)index {
- // This method gets called when a new bookmark item is created so
- // the container and property are set here.
- [aBookmarkItem setContainer:self
- property:AppleScript::kBookmarkItemsProperty];
- int position = [self calculatePositionOfBookmarkItemAt:index];
-
- BookmarkModel* model = [self bookmarkModel];
- if (!model)
- return;
-
- GURL url(base::SysNSStringToUTF8([aBookmarkItem URL]));
- if (!url.is_valid()) {
- AppleScript::SetError(AppleScript::errInvalidURL);
- return;
- }
-
- const BookmarkNode* node = model->AddURL(bookmarkNode_,
- position,
- string16(),
- url);
- if (!node) {
- AppleScript::SetError(AppleScript::errCreateBookmarkItem);
- return;
- }
-
- [aBookmarkItem setBookmarkNode:node];
-}
-
-- (void)removeFromBookmarkItemsAtIndex:(int)index {
- int position = [self calculatePositionOfBookmarkItemAt:index];
-
- BookmarkModel* model = [self bookmarkModel];
- if (!model)
- return;
-
- model->Remove(bookmarkNode_, position);
-}
-
-- (int)calculatePositionOfBookmarkFolderAt:(int)index {
- // Traverse through all the child nodes till the required node is found and
- // return its position.
- // AppleScript is 1-based therefore index is incremented by 1.
- ++index;
- int count = -1;
- while (index) {
- if (bookmarkNode_->GetChild(++count)->is_folder())
- --index;
- }
- return count;
-}
-
-- (int)calculatePositionOfBookmarkItemAt:(int)index {
- // Traverse through all the child nodes till the required node is found and
- // return its position.
- // AppleScript is 1-based therefore index is incremented by 1.
- ++index;
- int count = -1;
- while (index) {
- if (bookmarkNode_->GetChild(++count)->is_url())
- --index;
- }
- return count;
-}
-
-@end
diff --git a/chrome/browser/cocoa/applescript/bookmark_folder_applescript_unittest.mm b/chrome/browser/cocoa/applescript/bookmark_folder_applescript_unittest.mm
deleted file mode 100644
index 658f1fc..0000000
--- a/chrome/browser/cocoa/applescript/bookmark_folder_applescript_unittest.mm
+++ /dev/null
@@ -1,200 +0,0 @@
-// Copyright (c) 2010 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/scoped_nsobject.h"
-#include "base/sys_string_conversions.h"
-#import "chrome/browser/cocoa/applescript/bookmark_applescript_utils_unittest.h"
-#import "chrome/browser/cocoa/applescript/bookmark_folder_applescript.h"
-#import "chrome/browser/cocoa/applescript/bookmark_item_applescript.h"
-#import "chrome/browser/cocoa/applescript/constants_applescript.h"
-#import "chrome/browser/cocoa/applescript/error_applescript.h"
-#include "googleurl/src/gurl.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#import "testing/gtest_mac.h"
-#include "testing/platform_test.h"
-
-typedef BookmarkAppleScriptTest BookmarkFolderAppleScriptTest;
-
-namespace {
-
-// Test all the bookmark folders within.
-TEST_F(BookmarkFolderAppleScriptTest, BookmarkFolders) {
- NSArray* bookmarkFolders = [bookmarkBar_.get() bookmarkFolders];
-
- EXPECT_EQ(2U, [bookmarkFolders count]);
-
- BookmarkFolderAppleScript* f1 = [bookmarkFolders objectAtIndex:0];
- BookmarkFolderAppleScript* f2 = [bookmarkFolders objectAtIndex:1];
- EXPECT_NSEQ(@"f1", [f1 title]);
- EXPECT_NSEQ(@"f2", [f2 title]);
- EXPECT_EQ(2, [[f1 index] intValue]);
- EXPECT_EQ(4, [[f2 index] intValue]);
-
- for (BookmarkFolderAppleScript* bookmarkFolder in bookmarkFolders) {
- EXPECT_EQ([bookmarkFolder container], bookmarkBar_.get());
- EXPECT_NSEQ(AppleScript::kBookmarkFoldersProperty,
- [bookmarkFolder containerProperty]);
- }
-}
-
-// Insert a new bookmark folder.
-TEST_F(BookmarkFolderAppleScriptTest, InsertBookmarkFolder) {
- // Emulate what applescript would do when inserting a new bookmark folder.
- // Emulates a script like |set var to make new bookmark folder with
- // properties {title:"foo"}|.
- scoped_nsobject<BookmarkFolderAppleScript> bookmarkFolder(
- [[BookmarkFolderAppleScript alloc] init]);
- scoped_nsobject<NSNumber> var([[bookmarkFolder.get() uniqueID] copy]);
- [bookmarkFolder.get() setTitle:@"foo"];
- [bookmarkBar_.get() insertInBookmarkFolders:bookmarkFolder.get()];
-
- // Represents the bookmark folder after its added.
- BookmarkFolderAppleScript* bf =
- [[bookmarkBar_.get() bookmarkFolders] objectAtIndex:2];
- EXPECT_NSEQ(@"foo", [bf title]);
- EXPECT_EQ([bf container], bookmarkBar_.get());
- EXPECT_NSEQ(AppleScript::kBookmarkFoldersProperty,
- [bf containerProperty]);
- EXPECT_NSEQ(var.get(), [bf uniqueID]);
-}
-
-// Insert a new bookmark folder at a particular position.
-TEST_F(BookmarkFolderAppleScriptTest, InsertBookmarkFolderAtPosition) {
- // Emulate what applescript would do when inserting a new bookmark folder.
- // Emulates a script like |set var to make new bookmark folder with
- // properties {title:"foo"} at after bookmark folder 1|.
- scoped_nsobject<BookmarkFolderAppleScript> bookmarkFolder(
- [[BookmarkFolderAppleScript alloc] init]);
- scoped_nsobject<NSNumber> var([[bookmarkFolder.get() uniqueID] copy]);
- [bookmarkFolder.get() setTitle:@"foo"];
- [bookmarkBar_.get() insertInBookmarkFolders:bookmarkFolder.get() atIndex:1];
-
- // Represents the bookmark folder after its added.
- BookmarkFolderAppleScript* bf =
- [[bookmarkBar_.get() bookmarkFolders] objectAtIndex:1];
- EXPECT_NSEQ(@"foo", [bf title]);
- EXPECT_EQ([bf container], bookmarkBar_.get());
- EXPECT_NSEQ(AppleScript::kBookmarkFoldersProperty, [bf containerProperty]);
- EXPECT_NSEQ(var.get(), [bf uniqueID]);
-}
-
-// Delete bookmark folders.
-TEST_F(BookmarkFolderAppleScriptTest, DeleteBookmarkFolders) {
- unsigned int folderCount = 2, itemCount = 3;
- for (unsigned int i = 0; i < folderCount; ++i) {
- EXPECT_EQ(folderCount - i, [[bookmarkBar_.get() bookmarkFolders] count]);
- EXPECT_EQ(itemCount, [[bookmarkBar_.get() bookmarkItems] count]);
- [bookmarkBar_.get() removeFromBookmarkFoldersAtIndex:0];
- }
-}
-
-// Test all the bookmark items within.
-TEST_F(BookmarkFolderAppleScriptTest, BookmarkItems) {
- NSArray* bookmarkItems = [bookmarkBar_.get() bookmarkItems];
-
- EXPECT_EQ(3U, [bookmarkItems count]);
-
- BookmarkItemAppleScript* i1 = [bookmarkItems objectAtIndex:0];
- BookmarkItemAppleScript* i2 = [bookmarkItems objectAtIndex:1];
- BookmarkItemAppleScript* i3 = [bookmarkItems objectAtIndex:2];
- EXPECT_NSEQ(@"a", [i1 title]);
- EXPECT_NSEQ(@"d", [i2 title]);
- EXPECT_NSEQ(@"h", [i3 title]);
- EXPECT_EQ(1, [[i1 index] intValue]);
- EXPECT_EQ(3, [[i2 index] intValue]);
- EXPECT_EQ(5, [[i3 index] intValue]);
-
- for (BookmarkItemAppleScript* bookmarkItem in bookmarkItems) {
- EXPECT_EQ([bookmarkItem container], bookmarkBar_.get());
- EXPECT_NSEQ(AppleScript::kBookmarkItemsProperty,
- [bookmarkItem containerProperty]);
- }
-}
-
-// Insert a new bookmark item.
-TEST_F(BookmarkFolderAppleScriptTest, InsertBookmarkItem) {
- // Emulate what applescript would do when inserting a new bookmark folder.
- // Emulates a script like |set var to make new bookmark item with
- // properties {title:"Google", URL:"http://google.com"}|.
- scoped_nsobject<BookmarkItemAppleScript> bookmarkItem(
- [[BookmarkItemAppleScript alloc] init]);
- scoped_nsobject<NSNumber> var([[bookmarkItem.get() uniqueID] copy]);
- [bookmarkItem.get() setTitle:@"Google"];
- [bookmarkItem.get() setURL:@"http://google.com"];
- [bookmarkBar_.get() insertInBookmarkItems:bookmarkItem.get()];
-
- // Represents the bookmark item after its added.
- BookmarkItemAppleScript* bi =
- [[bookmarkBar_.get() bookmarkItems] objectAtIndex:3];
- EXPECT_NSEQ(@"Google", [bi title]);
- EXPECT_EQ(GURL("http://google.com/"),
- GURL(base::SysNSStringToUTF8([bi URL])));
- EXPECT_EQ([bi container], bookmarkBar_.get());
- EXPECT_NSEQ(AppleScript::kBookmarkItemsProperty, [bi containerProperty]);
- EXPECT_NSEQ(var.get(), [bi uniqueID]);
-
- // Test to see no bookmark item is created when no/invlid URL is entered.
- scoped_nsobject<FakeScriptCommand> fakeScriptCommand(
- [[FakeScriptCommand alloc] init]);
- bookmarkItem.reset([[BookmarkItemAppleScript alloc] init]);
- [bookmarkBar_.get() insertInBookmarkItems:bookmarkItem.get()];
- EXPECT_EQ((int)AppleScript::errInvalidURL,
- [fakeScriptCommand.get() scriptErrorNumber]);
-}
-
-// Insert a new bookmark item at a particular position.
-TEST_F(BookmarkFolderAppleScriptTest, InsertBookmarkItemAtPosition) {
- // Emulate what applescript would do when inserting a new bookmark item.
- // Emulates a script like |set var to make new bookmark item with
- // properties {title:"XKCD", URL:"http://xkcd.org}
- // at after bookmark item 1|.
- scoped_nsobject<BookmarkItemAppleScript> bookmarkItem(
- [[BookmarkItemAppleScript alloc] init]);
- scoped_nsobject<NSNumber> var([[bookmarkItem.get() uniqueID] copy]);
- [bookmarkItem.get() setTitle:@"XKCD"];
- [bookmarkItem.get() setURL:@"http://xkcd.org"];
-
- [bookmarkBar_.get() insertInBookmarkItems:bookmarkItem.get() atIndex:1];
-
- // Represents the bookmark item after its added.
- BookmarkItemAppleScript* bi =
- [[bookmarkBar_.get() bookmarkItems] objectAtIndex:1];
- EXPECT_NSEQ(@"XKCD", [bi title]);
- EXPECT_EQ(GURL("http://xkcd.org/"),
- GURL(base::SysNSStringToUTF8([bi URL])));
- EXPECT_EQ([bi container], bookmarkBar_.get());
- EXPECT_NSEQ(AppleScript::kBookmarkItemsProperty,
- [bi containerProperty]);
- EXPECT_NSEQ(var.get(), [bi uniqueID]);
-
- // Test to see no bookmark item is created when no/invlid URL is entered.
- scoped_nsobject<FakeScriptCommand> fakeScriptCommand(
- [[FakeScriptCommand alloc] init]);
- bookmarkItem.reset([[BookmarkItemAppleScript alloc] init]);
- [bookmarkBar_.get() insertInBookmarkItems:bookmarkItem.get() atIndex:1];
- EXPECT_EQ((int)AppleScript::errInvalidURL,
- [fakeScriptCommand.get() scriptErrorNumber]);
-}
-
-// Delete bookmark items.
-TEST_F(BookmarkFolderAppleScriptTest, DeleteBookmarkItems) {
- unsigned int folderCount = 2, itemCount = 3;
- for (unsigned int i = 0; i < itemCount; ++i) {
- EXPECT_EQ(folderCount, [[bookmarkBar_.get() bookmarkFolders] count]);
- EXPECT_EQ(itemCount - i, [[bookmarkBar_.get() bookmarkItems] count]);
- [bookmarkBar_.get() removeFromBookmarkItemsAtIndex:0];
- }
-}
-
-// Set and get title.
-TEST_F(BookmarkFolderAppleScriptTest, GetAndSetTitle) {
- NSArray* bookmarkFolders = [bookmarkBar_.get() bookmarkFolders];
- BookmarkFolderAppleScript* folder1 = [bookmarkFolders objectAtIndex:0];
- [folder1 setTitle:@"Foo"];
- EXPECT_NSEQ(@"Foo", [folder1 title]);
-}
-
-} // namespace
diff --git a/chrome/browser/cocoa/applescript/bookmark_item_applescript.h b/chrome/browser/cocoa/applescript/bookmark_item_applescript.h
deleted file mode 100644
index 97c07af..0000000
--- a/chrome/browser/cocoa/applescript/bookmark_item_applescript.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (c) 2010 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_COCOA_APPLESCRIPT_BOOKMARK_ITEM_APPLESCRIPT_H_
-#define CHROME_BROWSER_COCOA_APPLESCRIPT_BOOKMARK_ITEM_APPLESCRIPT_H_
-
-#import <Cocoa/Cocoa.h>
-
-#import "chrome/browser/cocoa/applescript/bookmark_node_applescript.h"
-
-// Represents a bookmark item scriptable object in applescript.
-@interface BookmarkItemAppleScript : BookmarkNodeAppleScript {
- @private
- // Contains the temporary title when a user creates a new item with
- // title specified like
- // |make new bookmarks item with properties {title:"foo"}|.
- NSString* tempURL_;
-}
-
-// Assigns a node, sets its unique ID and also copies temporary values.
-- (void)setBookmarkNode:(const BookmarkNode*)aBookmarkNode;
-
-// Returns the URL that the bookmark item holds.
-- (NSString*)URL;
-
-// Sets the URL of the bookmark item, displays error in applescript console
-// if URL is invalid.
-- (void)setURL:(NSString*)aURL;
-
-@end
-
-#endif // CHROME_BROWSER_COCOA_APPLESCRIPT_BOOKMARK_ITEM_APPLESCRIPT_H_
diff --git a/chrome/browser/cocoa/applescript/bookmark_item_applescript.mm b/chrome/browser/cocoa/applescript/bookmark_item_applescript.mm
deleted file mode 100644
index e42a764..0000000
--- a/chrome/browser/cocoa/applescript/bookmark_item_applescript.mm
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (c) 2010 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/cocoa/applescript/bookmark_item_applescript.h"
-
-#include "base/sys_string_conversions.h"
-#include "chrome/browser/bookmarks/bookmark_model.h"
-#import "chrome/browser/cocoa/applescript/error_applescript.h"
-#include "chrome/browser/profile_manager.h"
-
-@interface BookmarkItemAppleScript()
-@property (nonatomic, copy) NSString* tempURL;
-@end
-
-@implementation BookmarkItemAppleScript
-
-@synthesize tempURL = tempURL_;
-
-- (id)init {
- if ((self = [super init])) {
- [self setTempURL:@""];
- }
- return self;
-}
-
-- (void)dealloc {
- [tempURL_ release];
- [super dealloc];
-}
-
-- (void)setBookmarkNode:(const BookmarkNode*)aBookmarkNode {
- [super setBookmarkNode:aBookmarkNode];
- [self setURL:[self tempURL]];
-}
-
-- (NSString*)URL {
- if (!bookmarkNode_)
- return tempURL_;
-
- const GURL& url = bookmarkNode_->GetURL();
- return base::SysUTF8ToNSString(url.spec());
-}
-
-- (void)setURL:(NSString*)aURL {
- // If a scripter sets a URL before the node is added, URL is saved at a
- // temporary location.
- if (!bookmarkNode_) {
- [self setTempURL:aURL];
- return;
- }
-
- BookmarkModel* model = [self bookmarkModel];
- if (!model)
- return;
-
- GURL url(base::SysNSStringToUTF8(aURL));
- if (!url.is_valid()) {
- AppleScript::SetError(AppleScript::errInvalidURL);
- return;
- }
-
- model->SetURL(bookmarkNode_, url);
-}
-
-@end
diff --git a/chrome/browser/cocoa/applescript/bookmark_item_applescript_unittest.mm b/chrome/browser/cocoa/applescript/bookmark_item_applescript_unittest.mm
deleted file mode 100644
index 68289dc..0000000
--- a/chrome/browser/cocoa/applescript/bookmark_item_applescript_unittest.mm
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (c) 2010 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/scoped_nsobject.h"
-#include "base/sys_string_conversions.h"
-#import "chrome/browser/cocoa/applescript/bookmark_applescript_utils_unittest.h"
-#import "chrome/browser/cocoa/applescript/bookmark_item_applescript.h"
-#import "chrome/browser/cocoa/applescript/error_applescript.h"
-#include "googleurl/src/gurl.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#import "testing/gtest_mac.h"
-#include "testing/platform_test.h"
-
-typedef BookmarkAppleScriptTest BookmarkItemAppleScriptTest;
-
-namespace {
-
-// Set and get title.
-TEST_F(BookmarkItemAppleScriptTest, GetAndSetTitle) {
- NSArray* bookmarkItems = [bookmarkBar_.get() bookmarkItems];
- BookmarkItemAppleScript* item1 = [bookmarkItems objectAtIndex:0];
- [item1 setTitle:@"Foo"];
- EXPECT_NSEQ(@"Foo", [item1 title]);
-}
-
-// Set and get URL.
-TEST_F(BookmarkItemAppleScriptTest, GetAndSetURL) {
- NSArray* bookmarkItems = [bookmarkBar_.get() bookmarkItems];
- BookmarkItemAppleScript* item1 = [bookmarkItems objectAtIndex:0];
- [item1 setURL:@"http://foo-bar.org"];
- EXPECT_EQ(GURL("http://foo-bar.org"),
- GURL(base::SysNSStringToUTF8([item1 URL])));
-
- // If scripter enters invalid URL.
- scoped_nsobject<FakeScriptCommand> fakeScriptCommand(
- [[FakeScriptCommand alloc] init]);
- [item1 setURL:@"invalid-url.org"];
- EXPECT_EQ((int)AppleScript::errInvalidURL,
- [fakeScriptCommand.get() scriptErrorNumber]);
-}
-
-} // namespace
diff --git a/chrome/browser/cocoa/applescript/bookmark_node_applescript.h b/chrome/browser/cocoa/applescript/bookmark_node_applescript.h
deleted file mode 100644
index 7ec8856..0000000
--- a/chrome/browser/cocoa/applescript/bookmark_node_applescript.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (c) 2010 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_COCOA_APPLESCRIPT_BOOKMARK_NODE_APPLESCRIPT_H_
-#define CHROME_BROWSER_COCOA_APPLESCRIPT_BOOKMARK_NODE_APPLESCRIPT_H_
-
-#import <Cocoa/Cocoa.h>
-
-#import "chrome/browser/cocoa/applescript/element_applescript.h"
-
-class BookmarkModel;
-class BookmarkNode;
-
-// Contains all the elements that are common to both a bookmark folder and
-// bookmark item.
-@interface BookmarkNodeAppleScript : ElementAppleScript {
- @protected
- const BookmarkNode* bookmarkNode_; // weak.
- // Contains the temporary title when a scripter creates a new folder/item with
- // title specified like
- // |make new bookmark folder with properties {title:"foo"}|.
- NSString* tempTitle_;
-}
-
-// Does not actually create a folder/item but just sets its ID, the folder is
-// created in insertInBookmarksFolder: in the corresponding bookmarks folder.
-- (id)init;
-
-// Does not make a folder/item but instead uses an existing one.
-- (id)initWithBookmarkNode:(const BookmarkNode*)aBookmarkNode;
-
-// Assigns a node, sets its unique ID and also copies temporary values.
-- (void)setBookmarkNode:(const BookmarkNode*)aBookmarkNode;
-
-// Get and Set title.
-- (NSString*)title;
-- (void)setTitle:(NSString*)aTitle;
-
-// Returns the index with respect to its parent bookmark folder.
-- (NSNumber*)index;
-
-// Returns the bookmark model of the browser, returns NULL if there is an error.
-- (BookmarkModel*)bookmarkModel;
-
-@end
-
-#endif // CHROME_BROWSER_COCOA_APPLESCRIPT_BOOKMARK_NODE_APPLESCRIPT_H_
diff --git a/chrome/browser/cocoa/applescript/bookmark_node_applescript.mm b/chrome/browser/cocoa/applescript/bookmark_node_applescript.mm
deleted file mode 100644
index 9ad57bd..0000000
--- a/chrome/browser/cocoa/applescript/bookmark_node_applescript.mm
+++ /dev/null
@@ -1,130 +0,0 @@
-// Copyright (c) 2010 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/cocoa/applescript/bookmark_node_applescript.h"
-
-#include "base/logging.h"
-#include "base/sys_string_conversions.h"
-#import "base/scoped_nsobject.h"
-#import "chrome/browser/app_controller_mac.h"
-#include "chrome/browser/bookmarks/bookmark_model.h"
-#import "chrome/browser/chrome_browser_application_mac.h"
-#import "chrome/browser/cocoa/applescript/error_applescript.h"
-#include "chrome/browser/profile.h"
-#import "chrome/browser/cocoa/applescript/bookmark_item_applescript.h"
-
-@interface BookmarkNodeAppleScript()
-@property (nonatomic, copy) NSString* tempTitle;
-@end
-
-@implementation BookmarkNodeAppleScript
-
-@synthesize tempTitle = tempTitle_;
-
-- (id)init {
- if ((self = [super init])) {
- BookmarkModel* model = [self bookmarkModel];
- if (!model) {
- [self release];
- return nil;
- }
-
- scoped_nsobject<NSNumber> numID(
- [[NSNumber alloc] initWithLongLong:model->next_node_id()]);
- [self setUniqueID:numID];
- [self setTempTitle:@""];
- }
- return self;
-}
-
-- (void)dealloc {
- [tempTitle_ release];
- [super dealloc];
-}
-
-
-- (id)initWithBookmarkNode:(const BookmarkNode*)aBookmarkNode {
- if (!aBookmarkNode) {
- [self release];
- return nil;
- }
-
- if ((self = [super init])) {
- // It is safe to be weak, if a bookmark item/folder goes away
- // (eg user deleting a folder) the applescript runtime calls
- // bookmarkFolders/bookmarkItems in BookmarkFolderAppleScript
- // and this particular bookmark item/folder is never returned.
- bookmarkNode_ = aBookmarkNode;
-
- scoped_nsobject<NSNumber> numID(
- [[NSNumber alloc] initWithLongLong:aBookmarkNode->id()]);
- [self setUniqueID:numID];
- }
- return self;
-}
-
-- (void)setBookmarkNode:(const BookmarkNode*)aBookmarkNode {
- DCHECK(aBookmarkNode);
- // It is safe to be weak, if a bookmark item/folder goes away
- // (eg user deleting a folder) the applescript runtime calls
- // bookmarkFolders/bookmarkItems in BookmarkFolderAppleScript
- // and this particular bookmark item/folder is never returned.
- bookmarkNode_ = aBookmarkNode;
-
- scoped_nsobject<NSNumber> numID(
- [[NSNumber alloc] initWithLongLong:aBookmarkNode->id()]);
- [self setUniqueID:numID];
-
- [self setTitle:[self tempTitle]];
-}
-
-- (NSString*)title {
- if (!bookmarkNode_)
- return tempTitle_;
-
- return base::SysUTF16ToNSString(bookmarkNode_->GetTitle());
-}
-
-- (void)setTitle:(NSString*)aTitle {
- // If the scripter enters |make new bookmarks folder with properties
- // {title:"foo"}|, the node has not yet been created so title is stored in the
- // temp title.
- if (!bookmarkNode_) {
- [self setTempTitle:aTitle];
- return;
- }
-
- BookmarkModel* model = [self bookmarkModel];
- if (!model)
- return;
-
- model->SetTitle(bookmarkNode_, base::SysNSStringToUTF16(aTitle));
-}
-
-- (NSNumber*)index {
- const BookmarkNode* parent = bookmarkNode_->GetParent();
- int index = parent->IndexOfChild(bookmarkNode_);
- // NOTE: AppleScript is 1-Based.
- return [NSNumber numberWithInt:index+1];
-}
-
-- (BookmarkModel*)bookmarkModel {
- AppController* appDelegate = [NSApp delegate];
-
- Profile* defaultProfile = [appDelegate defaultProfile];
- if (!defaultProfile) {
- AppleScript::SetError(AppleScript::errGetProfile);
- return NULL;
- }
-
- BookmarkModel* model = defaultProfile->GetBookmarkModel();
- if (!model->IsLoaded()) {
- AppleScript::SetError(AppleScript::errBookmarkModelLoad);
- return NULL;
- }
-
- return model;
-}
-
-@end
diff --git a/chrome/browser/cocoa/applescript/browsercrapplication+applescript.h b/chrome/browser/cocoa/applescript/browsercrapplication+applescript.h
deleted file mode 100644
index 527df48..0000000
--- a/chrome/browser/cocoa/applescript/browsercrapplication+applescript.h
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (c) 2010 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_COCOA_APPLESCRIPT_BROWSERCRAPPLICATION_APPLESCRIPT_H_
-#define CHROME_BROWSER_COCOA_APPLESCRIPT_BROWSERCRAPPLICATION_APPLESCRIPT_H_
-
-#import <Cocoa/Cocoa.h>
-
-#import "chrome/browser/chrome_browser_application_mac.h"
-
-@class BookmarkFolderAppleScript;
-@class WindowAppleScript;
-
-// Represent the top level application scripting object in applescript.
-@interface BrowserCrApplication (AppleScriptAdditions)
-
-// Application window manipulation methods.
-// Returns an array of |WindowAppleScript*| of all windows present in the
-// application.
-- (NSArray*)appleScriptWindows;
-
-// Inserts a window at the beginning.
-- (void)insertInAppleScriptWindows:(WindowAppleScript*)aWindow;
-
-// Inserts a window at some position in the list.
-// Called by applescript which takes care of bounds checking, make sure of it
-// before calling directly.
-- (void)insertInAppleScriptWindows:(WindowAppleScript*)aWindow
- atIndex:(int)index;
-
-// Removes a window from the list.
-// Called by applescript which takes care of bounds checking, make sure of it
-// before calling directly.
-- (void)removeFromAppleScriptWindowsAtIndex:(int)index;
-
-// Always returns nil to indicate that it is the root container object.
-- (NSScriptObjectSpecifier*)objectSpecifier;
-
-// Returns the other bookmarks bookmark folder,
-// returns nil if there is an error.
-- (BookmarkFolderAppleScript*)otherBookmarks;
-
-// Returns the bookmarks bar bookmark folder, return nil if there is an error.
-- (BookmarkFolderAppleScript*)bookmarksBar;
-
-// Returns the Bookmarks Bar and Other Bookmarks Folders, each is of type
-// |BookmarkFolderAppleScript*|.
-- (NSArray*)bookmarkFolders;
-
-// Required functions, even though bookmarkFolders is declared as
-// read-only, cocoa scripting does not currently prevent writing.
-- (void)insertInBookmarksFolders:(id)aBookmarkFolder;
-- (void)insertInBookmarksFolders:(id)aBookmarkFolder atIndex:(int)index;
-- (void)removeFromBookmarksFoldersAtIndex:(int)index;
-
-@end
-
-#endif// CHROME_BROWSER_COCOA_APPLESCRIPT_BROWSERCRAPPLICATION_APPLESCRIPT_H_
diff --git a/chrome/browser/cocoa/applescript/browsercrapplication+applescript.mm b/chrome/browser/cocoa/applescript/browsercrapplication+applescript.mm
deleted file mode 100644
index 1ac4165..0000000
--- a/chrome/browser/cocoa/applescript/browsercrapplication+applescript.mm
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright (c) 2010 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/cocoa/applescript/browsercrapplication+applescript.h"
-
-#include "base/logging.h"
-#import "base/scoped_nsobject.h"
-#import "chrome/browser/app_controller_mac.h"
-#include "chrome/browser/bookmarks/bookmark_model.h"
-#include "chrome/browser/browser_list.h"
-#import "chrome/browser/cocoa/applescript/bookmark_folder_applescript.h"
-#import "chrome/browser/cocoa/applescript/constants_applescript.h"
-#import "chrome/browser/cocoa/applescript/error_applescript.h"
-#import "chrome/browser/cocoa/applescript/window_applescript.h"
-#include "chrome/browser/profile.h"
-
-@implementation BrowserCrApplication (AppleScriptAdditions)
-
-- (NSArray*)appleScriptWindows {
- NSMutableArray* appleScriptWindows = [NSMutableArray
- arrayWithCapacity:BrowserList::size()];
- // Iterate through all browsers and check if it closing,
- // if not add it to list.
- for (BrowserList::const_iterator browserIterator = BrowserList::begin();
- browserIterator != BrowserList::end(); ++browserIterator) {
- if ((*browserIterator)->IsAttemptingToCloseBrowser())
- continue;
-
- scoped_nsobject<WindowAppleScript> window(
- [[WindowAppleScript alloc] initWithBrowser:*browserIterator]);
- [window setContainer:NSApp
- property:AppleScript::kWindowsProperty];
- [appleScriptWindows addObject:window];
- }
- // Windows sorted by their index value, which is obtained by calling
- // orderedIndex: on each window.
- [appleScriptWindows sortUsingSelector:@selector(windowComparator:)];
- return appleScriptWindows;
-}
-
-- (void)insertInAppleScriptWindows:(WindowAppleScript*)aWindow {
- // This method gets called when a new window is created so
- // the container and property are set here.
- [aWindow setContainer:self
- property:AppleScript::kWindowsProperty];
-}
-
-- (void)insertInAppleScriptWindows:(WindowAppleScript*)aWindow
- atIndex:(int)index {
- // This method gets called when a new window is created so
- // the container and property are set here.
- [aWindow setContainer:self
- property:AppleScript::kWindowsProperty];
- // Note: AppleScript is 1-based.
- index--;
- [aWindow setOrderedIndex:[NSNumber numberWithInt:index]];
-}
-
-- (void)removeFromAppleScriptWindowsAtIndex:(int)index {
- [[[self appleScriptWindows] objectAtIndex:index]
- handlesCloseScriptCommand:nil];
-}
-
-- (NSScriptObjectSpecifier*)objectSpecifier {
- return nil;
-}
-
-- (BookmarkFolderAppleScript*)otherBookmarks {
- AppController* appDelegate = [NSApp delegate];
-
- Profile* defaultProfile = [appDelegate defaultProfile];
- if (!defaultProfile) {
- AppleScript::SetError(AppleScript::errGetProfile);
- return nil;
- }
-
- BookmarkModel* model = defaultProfile->GetBookmarkModel();
- if (!model->IsLoaded()) {
- AppleScript::SetError(AppleScript::errBookmarkModelLoad);
- return nil;
- }
-
- BookmarkFolderAppleScript* otherBookmarks =
- [[[BookmarkFolderAppleScript alloc]
- initWithBookmarkNode:model->other_node()] autorelease];
- [otherBookmarks setContainer:self
- property:AppleScript::kBookmarkFoldersProperty];
- return otherBookmarks;
-}
-
-- (BookmarkFolderAppleScript*)bookmarksBar {
- AppController* appDelegate = [NSApp delegate];
-
- Profile* defaultProfile = [appDelegate defaultProfile];
- if (!defaultProfile) {
- AppleScript::SetError(AppleScript::errGetProfile);
- return nil;
- }
-
- BookmarkModel* model = defaultProfile->GetBookmarkModel();
- if (!model->IsLoaded()) {
- AppleScript::SetError(AppleScript::errBookmarkModelLoad);
- return NULL;
- }
-
- BookmarkFolderAppleScript* bookmarksBar =
- [[[BookmarkFolderAppleScript alloc]
- initWithBookmarkNode:model->GetBookmarkBarNode()] autorelease];
- [bookmarksBar setContainer:self
- property:AppleScript::kBookmarkFoldersProperty];
- return bookmarksBar;
-}
-
-- (NSArray*)bookmarkFolders {
- BookmarkFolderAppleScript* otherBookmarks = [self otherBookmarks];
- BookmarkFolderAppleScript* bookmarksBar = [self bookmarksBar];
- NSArray* folderArray = [NSArray arrayWithObjects:otherBookmarks,
- bookmarksBar,
- nil];
- return folderArray;
-}
-
-- (void)insertInBookmarksFolders:(id)aBookmarkFolder {
- NOTIMPLEMENTED();
-}
-
-- (void)insertInBookmarksFolders:(id)aBookmarkFolder atIndex:(int)index {
- NOTIMPLEMENTED();
-}
-
-- (void)removeFromBookmarksFoldersAtIndex:(int)index {
- NOTIMPLEMENTED();
-}
-
-@end
diff --git a/chrome/browser/cocoa/applescript/browsercrapplication+applescript_test.mm b/chrome/browser/cocoa/applescript/browsercrapplication+applescript_test.mm
deleted file mode 100644
index 15c654f..0000000
--- a/chrome/browser/cocoa/applescript/browsercrapplication+applescript_test.mm
+++ /dev/null
@@ -1,107 +0,0 @@
-// Copyright (c) 2010 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>
-
-#import "chrome/browser/cocoa/applescript/browsercrapplication+applescript.h"
-#import "chrome/browser/cocoa/applescript/constants_applescript.h"
-#import "chrome/browser/cocoa/applescript/window_applescript.h"
-#include "chrome/browser/profile.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/test/in_process_browser_test.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "testing/gtest_mac.h"
-
-typedef InProcessBrowserTest BrowserCrApplicationAppleScriptTest;
-
-// Create windows of different |Type|.
-IN_PROC_BROWSER_TEST_F(BrowserCrApplicationAppleScriptTest, Creation) {
- // Create additional |Browser*| objects of different type.
- Profile* profile = browser()->profile();
- Browser* b1 = Browser::CreateForType(Browser::TYPE_POPUP, profile);
- Browser* b2 = Browser::CreateForApp("", NULL, profile, true);
- Browser* b3 = Browser::CreateForApp("", NULL, profile, false);
-
- EXPECT_EQ(4U, [[NSApp appleScriptWindows] count]);
- for (WindowAppleScript* window in [NSApp appleScriptWindows]) {
- EXPECT_NSEQ(AppleScript::kWindowsProperty,
- [window containerProperty]);
- EXPECT_NSEQ(NSApp, [window container]);
- }
-
- // Close the additional browsers.
- b1->CloseAllTabs();
- b2->CloseAllTabs();
- b3->CloseAllTabs();
-}
-
-// Insert a new window.
-IN_PROC_BROWSER_TEST_F(BrowserCrApplicationAppleScriptTest, InsertWindow) {
- // Emulate what applescript would do when creating a new window.
- // Emulate a script like |set var to make new window with properties
- // {visible:false}|.
- scoped_nsobject<WindowAppleScript> aWindow([[WindowAppleScript alloc] init]);
- scoped_nsobject<NSNumber> var([[aWindow.get() uniqueID] copy]);
- [aWindow.get() setValue:[NSNumber numberWithBool:YES] forKey:@"isVisible"];
-
- [NSApp insertInAppleScriptWindows:aWindow.get()];
-
- // Represents the window after it is added.
- WindowAppleScript* window = [[NSApp appleScriptWindows] objectAtIndex:0];
- EXPECT_NSEQ([NSNumber numberWithBool:YES],
- [aWindow.get() valueForKey:@"isVisible"]);
- EXPECT_EQ([window container], NSApp);
- EXPECT_NSEQ(AppleScript::kWindowsProperty,
- [window containerProperty]);
- EXPECT_NSEQ(var, [window uniqueID]);
-}
-
-// Inserting and deleting windows.
-IN_PROC_BROWSER_TEST_F(BrowserCrApplicationAppleScriptTest,
- InsertAndDeleteWindows) {
- scoped_nsobject<WindowAppleScript> aWindow;
- int count;
- // Create a bunch of windows.
- for (int i = 0; i < 5; ++i) {
- for (int j = 0; j < 3; ++j) {
- aWindow.reset([[WindowAppleScript alloc] init]);
- [NSApp insertInAppleScriptWindows:aWindow.get()];
- }
- count = 3 * i + 4;
- EXPECT_EQ(count, (int)[[NSApp appleScriptWindows] count]);
- }
-
- // Remove all the windows, just created.
- count = (int)[[NSApp appleScriptWindows] count];
- for (int i = 0; i < 5; ++i) {
- for(int j = 0; j < 3; ++j) {
- [NSApp removeFromAppleScriptWindowsAtIndex:0];
- }
- count = count - 3;
- EXPECT_EQ(count, (int)[[NSApp appleScriptWindows] count]);
- }
-}
-
-// Check for objectSpecifer of the root scripting object.
-IN_PROC_BROWSER_TEST_F(BrowserCrApplicationAppleScriptTest, ObjectSpecifier) {
- // Should always return nil to indicate its the root scripting object.
- EXPECT_EQ(nil, [NSApp objectSpecifier]);
-}
-
-// Bookmark folders at the root level.
-IN_PROC_BROWSER_TEST_F(BrowserCrApplicationAppleScriptTest, BookmarkFolders) {
- NSArray* bookmarkFolders = [NSApp bookmarkFolders];
- EXPECT_EQ(2U, [bookmarkFolders count]);
-
- for (BookmarkFolderAppleScript* bookmarkFolder in bookmarkFolders) {
- EXPECT_EQ(NSApp,
- [bookmarkFolder container]);
- EXPECT_NSEQ(AppleScript::kBookmarkFoldersProperty,
- [bookmarkFolder containerProperty]);
- }
-
- EXPECT_NSEQ(@"Other Bookmarks", [[NSApp otherBookmarks] title]);
- EXPECT_NSEQ(@"Bookmarks Bar", [[NSApp bookmarksBar] title]);
-}
-
diff --git a/chrome/browser/cocoa/applescript/constants_applescript.h b/chrome/browser/cocoa/applescript/constants_applescript.h
deleted file mode 100644
index 13a96df..0000000
--- a/chrome/browser/cocoa/applescript/constants_applescript.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (c) 2010 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_COCOA_APPLESCRIPT_CONSTANTS_APPLESCRIPT_H_
-#define CHROME_BROWSER_COCOA_APPLESCRIPT_CONSTANTS_APPLESCRIPT_H_
-
-#import <Cocoa/Cocoa.h>
-
-// This file contains the constant that are use to set the property of an
-// applescript scriptable item.
-namespace AppleScript {
-// Property to access windows.
-extern NSString* const kWindowsProperty;
-
-// Property to access tabs.
-extern NSString* const kTabsProperty;
-
-// Property to access bookmarks folders.
-extern NSString* const kBookmarkFoldersProperty;
-
-// Property to access bookmark items.
-extern NSString* const kBookmarkItemsProperty;
-
-// To indicate a window in normal mode.
-extern NSString* const kNormalWindowMode;
-
-// To indicate a window in incognito mode.
-extern NSString* const kIncognitoWindowMode;
-}
-#endif // CHROME_BROWSER_COCOA_APPLESCRIPT_CONSTANTS_APPLESCRIPT_H_
diff --git a/chrome/browser/cocoa/applescript/constants_applescript.mm b/chrome/browser/cocoa/applescript/constants_applescript.mm
deleted file mode 100644
index 3eddc9a..0000000
--- a/chrome/browser/cocoa/applescript/constants_applescript.mm
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (c) 2010 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/cocoa/applescript/constants_applescript.h"
-
-namespace AppleScript {
-// Property to access windows.
-NSString* const kWindowsProperty = @"appleScriptWindows";
-
-// Property to access tabs.
-NSString* const kTabsProperty = @"tabs";
-
-// Property to access bookmarks folders.
-NSString* const kBookmarkFoldersProperty = @"bookmarkFolders";
-
-// Property to access bookmark items.
-NSString* const kBookmarkItemsProperty = @"bookmarkItems";
-
-// To indicate a window in normal mode.
-NSString* const kNormalWindowMode = @"normal";
-
-// To indicate a window in incognito mode.
-NSString* const kIncognitoWindowMode = @"incognito";
-}
diff --git a/chrome/browser/cocoa/applescript/element_applescript.h b/chrome/browser/cocoa/applescript/element_applescript.h
deleted file mode 100644
index ba3d65c..0000000
--- a/chrome/browser/cocoa/applescript/element_applescript.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (c) 2010 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_COCOA_APPLESCRIPT_ELEMENT_APPLESCRIPT_H_
-#define CHROME_BROWSER_COCOA_APPLESCRIPT_ELEMENT_APPLESCRIPT_H_
-
-#import <Cocoa/Cocoa.h>
-
-// This class is the root class for all the other applescript classes.
-// It takes care of all the infrastructure type operations.
-@interface ElementAppleScript : NSObject {
- @protected
- // Used by the applescript runtime to identify each unique scriptable object.
- NSNumber* uniqueID_;
- // Used by object specifier to find a scriptable object's place in a
- // collection.
- id container_;
- NSString* containerProperty_;
-}
-
-@property (nonatomic, copy) NSNumber* uniqueID;
-@property (nonatomic, retain) id container;
-@property (nonatomic, copy) NSString* containerProperty;
-
-// Calculates the objectspecifier by using the uniqueID, container and
-// container property.
-// An object specifier is used to identify objects within a
-// collection.
-- (NSScriptObjectSpecifier*)objectSpecifier;
-
-// Sets both container and property, retains container and copies property.
-- (void)setContainer:(id)value property:(NSString*)property;
-
-@end
-
-#endif// CHROME_BROWSER_COCOA_APPLESCRIPT_ELEMENT_APPLESCRIPT_H_
diff --git a/chrome/browser/cocoa/applescript/element_applescript.mm b/chrome/browser/cocoa/applescript/element_applescript.mm
deleted file mode 100644
index 270fd25..0000000
--- a/chrome/browser/cocoa/applescript/element_applescript.mm
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) 2010 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/cocoa/applescript/element_applescript.h"
-
-@implementation ElementAppleScript
-
-@synthesize uniqueID = uniqueID_;
-@synthesize container = container_;
-@synthesize containerProperty = containerProperty_;
-
-// calling objectSpecifier asks an object to return an object specifier
-// record referring to itself. You must call setContainer:property: before
-// you can call this method.
-- (NSScriptObjectSpecifier*)objectSpecifier {
- return [[NSUniqueIDSpecifier allocWithZone:[self zone]]
- initWithContainerClassDescription:
- (NSScriptClassDescription*)[[self container] classDescription]
- containerSpecifier:
- [[self container] objectSpecifier]
- key:[self containerProperty]
- uniqueID:[self uniqueID]];
-}
-
-- (void)setContainer:(id)value property:(NSString*)property {
- [self setContainer:value];
- [self setContainerProperty:property];
-}
-
-- (void)dealloc {
- [uniqueID_ release];
- [container_ release];
- [containerProperty_ release];
- [super dealloc];
-}
-
-@end
diff --git a/chrome/browser/cocoa/applescript/error_applescript.h b/chrome/browser/cocoa/applescript/error_applescript.h
deleted file mode 100644
index 2635b2f..0000000
--- a/chrome/browser/cocoa/applescript/error_applescript.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (c) 2010 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_COCOA_APPLESCRIPT_ERROR_APPLESCRIPT_H_
-#define CHROME_BROWSER_COCOA_APPLESCRIPT_ERROR_APPLESCRIPT_H_
-
-#import <Cocoa/Cocoa.h>
-
-namespace AppleScript {
-
-enum ErrorCode {
- // Error when default profile cannot be obtained.
- errGetProfile = 1,
- // Error when bookmark model fails to load.
- errBookmarkModelLoad,
- // Error when bookmark folder cannot be created.
- errCreateBookmarkFolder,
- // Error when bookmark item cannot be created.
- errCreateBookmarkItem,
- // Error when URL entered is invalid.
- errInvalidURL,
- // Error when printing cannot be initiated.
- errInitiatePrinting,
- // Error when invalid tab save type is entered.
- errInvalidSaveType,
- // Error when invalid browser mode is entered.
- errInvalidMode,
- // Error when tab index is out of bounds.
- errInvalidTabIndex,
- // Error when mode is set after browser window is created.
- errSetMode,
- // Error when index of browser window is out of bounds.
- errWrongIndex
-};
-
-// This function sets an error message to the currently executing command.
-void SetError(ErrorCode errorCode);
-}
-
-#endif // CHROME_BROWSER_COCOA_APPLESCRIPT_ERROR_APPLESCRIPT_H_
diff --git a/chrome/browser/cocoa/applescript/error_applescript.mm b/chrome/browser/cocoa/applescript/error_applescript.mm
deleted file mode 100644
index cc25ad3..0000000
--- a/chrome/browser/cocoa/applescript/error_applescript.mm
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) 2010 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/cocoa/applescript/error_applescript.h"
-
-#import "app/l10n_util_mac.h"
-#include "base/logging.h"
-#include "grit/generated_resources.h"
-
-void AppleScript::SetError(AppleScript::ErrorCode errorCode) {
- using namespace l10n_util;
- NSScriptCommand* current_command = [NSScriptCommand currentCommand];
- [current_command setScriptErrorNumber:(int)errorCode];
- NSString* error_string = @"";
- switch (errorCode) {
- case errGetProfile:
- error_string = GetNSString(IDS_GET_PROFILE_ERROR_APPLESCRIPT_MAC);
- break;
- case errBookmarkModelLoad:
- error_string = GetNSString(IDS_BOOKMARK_MODEL_LOAD_ERROR_APPLESCRIPT_MAC);
- break;
- case errCreateBookmarkFolder:
- error_string =
- GetNSString(IDS_CREATE_BOOKMARK_FOLDER_ERROR_APPLESCRIPT_MAC);
- break;
- case errCreateBookmarkItem:
- error_string =
- GetNSString(IDS_CREATE_BOOKMARK_ITEM_ERROR_APPLESCRIPT_MAC);
- break;
- case errInvalidURL:
- error_string = GetNSString(IDS_INVALID_URL_APPLESCRIPT_MAC);
- break;
- case errInitiatePrinting:
- error_string = GetNSString(IDS_INITIATE_PRINTING_ERROR_APPLESCRIPT_MAC);
- break;
- case errInvalidSaveType:
- error_string = GetNSString(IDS_INVALID_SAVE_TYPE_ERROR_APPLESCRIPT_MAC);
- break;
- case errInvalidMode:
- error_string = GetNSString(IDS_INVALID_MODE_ERROR_APPLESCRIPT_MAC);
- break;
- case errInvalidTabIndex:
- error_string = GetNSString(IDS_INVALID_TAB_INDEX_APPLESCRIPT_MAC);
- break;
- case errSetMode:
- error_string = GetNSString(IDS_SET_MODE_APPLESCRIPT_MAC);
- break;
- case errWrongIndex:
- error_string = GetNSString(IDS_WRONG_INDEX_ERROR_APPLESCRIPT_MAC);
- break;
- default:
- NOTREACHED();
- }
- [current_command setScriptErrorString:error_string];
-}
diff --git a/chrome/browser/cocoa/applescript/examples/advanced_tab_manipulation.applescript b/chrome/browser/cocoa/applescript/examples/advanced_tab_manipulation.applescript
deleted file mode 100644
index d45bd86..0000000
--- a/chrome/browser/cocoa/applescript/examples/advanced_tab_manipulation.applescript
+++ /dev/null
@@ -1,24 +0,0 @@
--- Copyright (c) 2010 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.
-
-tell application "Chromium"
- tell tab 1 of window 1
- print -- Prints the tab, prompts the user for location.
- end tell
-
- tell tab 1 of window 1
- save in "/Users/Foo/Documents/Google" as "only html"
- -- Saves the contents of the tab without the accompanying resources.
-
- save in "/Users/Foo/Documents/Google" as "complete html"
- -- Saves the contents of the tab with the accompanying resources.
-
- -- Note: both the |in| and |as| part are optional, without it user is
- -- prompted for one.
- end tell
-
- tell tab 1 of window 1
- view source -- View the HTML of the tab in a new tab.
- end tell
-end tell
diff --git a/chrome/browser/cocoa/applescript/examples/app_info.applescript b/chrome/browser/cocoa/applescript/examples/app_info.applescript
deleted file mode 100644
index 8377e14..0000000
--- a/chrome/browser/cocoa/applescript/examples/app_info.applescript
+++ /dev/null
@@ -1,9 +0,0 @@
--- Copyright (c) 2010 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.
-
--- Gets basic information about the app.
-tell application "Chromium"
- set var1 to name
- set var2 to version
-end tell
diff --git a/chrome/browser/cocoa/applescript/examples/bookmark_current_tabs.applescript b/chrome/browser/cocoa/applescript/examples/bookmark_current_tabs.applescript
deleted file mode 100644
index 6e88268..0000000
--- a/chrome/browser/cocoa/applescript/examples/bookmark_current_tabs.applescript
+++ /dev/null
@@ -1,23 +0,0 @@
--- Copyright (c) 2010 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.
-
--- This script bookmarks the currently open tabs of a window.
-tell application "Chromium"
- set url_list to {}
- set title_list to {}
- tell window 1
- repeat with i from 1 to (count tabs)
- set end of url_list to (URL of tab i)
- set end of title_list to (title of tab i)
- end repeat
- end tell
- tell bookmarks bar
- set var to make new bookmark folder with properties {title:"New"}
- tell var
- repeat with i from 1 to (count url_list)
- make new bookmark item with properties {URL:(item i of url_list), title:(item i of title_list)}
- end repeat
- end tell
- end tell
-end tell \ No newline at end of file
diff --git a/chrome/browser/cocoa/applescript/examples/copy_html.applescript b/chrome/browser/cocoa/applescript/examples/copy_html.applescript
deleted file mode 100644
index fd7b4e0..0000000
--- a/chrome/browser/cocoa/applescript/examples/copy_html.applescript
+++ /dev/null
@@ -1,16 +0,0 @@
--- Copyright (c) 2010 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.
-
--- This script copies the HTML of a tab to a TextEdit document.
-tell application "Chromium"
- tell tab 1 of window 1 to view source
- repeat while (loading of tab 2 of window 1)
- end repeat
- tell tab 2 of window 1 to select all
- tell tab 2 of window 1 to copy selection
-end tell
-
-tell application "TextEdit"
- set text of document 1 to the clipboard
-end tell
diff --git a/chrome/browser/cocoa/applescript/examples/delete_bookmarks.applescript b/chrome/browser/cocoa/applescript/examples/delete_bookmarks.applescript
deleted file mode 100644
index 341b100..0000000
--- a/chrome/browser/cocoa/applescript/examples/delete_bookmarks.applescript
+++ /dev/null
@@ -1,13 +0,0 @@
--- Copyright (c) 2010 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.
-
--- This script deletes all the items within a bookmark folder.
-tell application "Chromium"
- set var to bookmark folder "New" of bookmarks bar
- -- Change the folder to whichever you want.
- tell var
- delete every bookmark item
- delete every bookmark folder
- end tell
-end tell
diff --git a/chrome/browser/cocoa/applescript/examples/execute_javascript.applescript b/chrome/browser/cocoa/applescript/examples/execute_javascript.applescript
deleted file mode 100644
index 33a34b4..0000000
--- a/chrome/browser/cocoa/applescript/examples/execute_javascript.applescript
+++ /dev/null
@@ -1,10 +0,0 @@
--- Copyright (c) 2010 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.
-
--- This script execute a string of javascript code.
-tell application "Chromium"
- tell tab 1 of window 1
- execute javascript "alert('Hello World')"
- end tell
-end tell
diff --git a/chrome/browser/cocoa/applescript/examples/open_tabs_from_bookmark_folder.applescript b/chrome/browser/cocoa/applescript/examples/open_tabs_from_bookmark_folder.applescript
deleted file mode 100644
index af36fc1..0000000
--- a/chrome/browser/cocoa/applescript/examples/open_tabs_from_bookmark_folder.applescript
+++ /dev/null
@@ -1,12 +0,0 @@
--- Copyright (c) 2010 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.
-
-tell application "Chromium"
- set var to bookmark folder "New" of bookmarks bar
- -- Change the folder to whichever you want.
- repeat with i in (bookmark items of var)
- set u to URL of i
- tell window 1 to make new tab with properties {u}
- end repeat
-end tell
diff --git a/chrome/browser/cocoa/applescript/examples/quit_app.applescript b/chrome/browser/cocoa/applescript/examples/quit_app.applescript
deleted file mode 100644
index a6bdd1f..0000000
--- a/chrome/browser/cocoa/applescript/examples/quit_app.applescript
+++ /dev/null
@@ -1,8 +0,0 @@
--- Copyright (c) 2010 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.
-
--- Quits the application, useful in cases where you want to schedule things.
-tell application "Chromium"
- quit
-end tell
diff --git a/chrome/browser/cocoa/applescript/examples/tab_manipulation.applescript b/chrome/browser/cocoa/applescript/examples/tab_manipulation.applescript
deleted file mode 100644
index 9038c17..0000000
--- a/chrome/browser/cocoa/applescript/examples/tab_manipulation.applescript
+++ /dev/null
@@ -1,45 +0,0 @@
--- Copyright (c) 2010 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.
-
--- Contains some common tab manipulation commands.
-tell application "Chromium"
- tell window 1 to make new tab with properties {URL:"http://google.com"}
- -- create a new tab and navigate to a particular URL.
-
- set var to active tab index of window 1
- set active tab index of window 1 to (var - 1) -- Select the previous tab.
-
- set var to active tab index of window 1
- set active tab index of window 1 to (var + 1) -- Select the next tab.
-
- get title of tab 1 of window 1 -- Get the URL that the user can see.
-
- get loading of tab 1 of window 1 -- Check if a tab is loading.
-
- -- Common edit/manipulation commands.
- tell tab 1 of window 1
- undo
-
- redo
-
- cut selection -- Cut a piece of text and place it on the system clipboard.
-
- copy selection -- Copy a piece of text and place it on the system clipboard.
-
- paste selection -- Paste a text from the system clipboard.
-
- select all
- end tell
-
- -- Common navigation commands.
- tell tab 1 of window 1
- go back
-
- go forward
-
- reload
-
- stop
- end tell
-end tell
diff --git a/chrome/browser/cocoa/applescript/examples/tab_navigation.applescript b/chrome/browser/cocoa/applescript/examples/tab_navigation.applescript
deleted file mode 100644
index 2337869..0000000
--- a/chrome/browser/cocoa/applescript/examples/tab_navigation.applescript
+++ /dev/null
@@ -1,13 +0,0 @@
--- Copyright (c) 2010 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.
-
-tell application "Chromium"
- tell window 1
- -- creates a new tab and navigates to a particular URL.
- make new tab with properties {URL:"http://google.com"}
- -- Duplicate a tab.
- set var to URL of tab 2
- make new tab with properties {URL:var}
- end tell
-end tell
diff --git a/chrome/browser/cocoa/applescript/examples/window_creation.applescript b/chrome/browser/cocoa/applescript/examples/window_creation.applescript
deleted file mode 100644
index fc1486a..0000000
--- a/chrome/browser/cocoa/applescript/examples/window_creation.applescript
+++ /dev/null
@@ -1,10 +0,0 @@
--- Copyright (c) 2010 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.
-
--- creates 2 windows, one in normal mode and another in incognito mode.
-tell application "Chromium"
- make new window
- make new window with properties {mode:"incognito"}
- count windows -- count how many windows are currently open.
-end tell
diff --git a/chrome/browser/cocoa/applescript/examples/window_operations.applescript b/chrome/browser/cocoa/applescript/examples/window_operations.applescript
deleted file mode 100644
index 90a0288..0000000
--- a/chrome/browser/cocoa/applescript/examples/window_operations.applescript
+++ /dev/null
@@ -1,22 +0,0 @@
--- Copyright (c) 2010 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.
-
--- Contains usage of common window operations.
-tell application "Chromium"
- get URL of active tab of window 1 -- The URL currently being seen.
-
- set minimized of window 1 to true -- Minimizes a window.
- set minimized of window 1 to false -- Maximizes a window.
-
- get mode of window 1
- -- Checks if a window is in |normal mode| or |incognito mode|
-
- set visible of window 1 to true -- Hides a window.
- set visible of window 1 to false -- UnHides a window.
-
- -- Open multiple tabs.
- set active tab index of window 1 to 2 -- Selects the second tab.
-
-
-end tell
diff --git a/chrome/browser/cocoa/applescript/scripting.sdef b/chrome/browser/cocoa/applescript/scripting.sdef
deleted file mode 100644
index b67b2b7..0000000
--- a/chrome/browser/cocoa/applescript/scripting.sdef
+++ /dev/null
@@ -1,304 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
-<dictionary title="Dictionary">
- <!--
- STANDARD SUITE
- -->
- <suite name="Standard Suite" code="core" description="Common classes and commands for all applications.">
- <cocoa name="NSCoreSuite"/>
- <class name="application" code="capp" description="The application&apos;s top-level scripting object.">
- <cocoa class="BrowserCrApplication"/>
- <element description="The windows contained within this application, ordered front to back." type="window">
- <cocoa key="appleScriptWindows"/>
- </element>
- <property name="name" code="pnam" description="The name of the application." type="text" access="r"/>
- <property name="frontmost" code="pisf" description="Is this the frontmost (active) application?" type="boolean" access="r">
- <cocoa key="isActive"/>
- </property>
- <property name="version" code="vers" description="The version of the application." type="text" access="r"/>
- <responds-to command="quit">
- <cocoa method="handleQuitScriptCommand:"/>
- </responds-to>
- </class>
- <class name="window" code="cwin" description="A window.">
- <cocoa class="WindowAppleScript"/>
- <element description="The tabs contained within the window." type="tab">
- <cocoa key="tabs"/>
- </element>
- <property name="name" code="pnam" description="The full title of the window." type="text" access="r">
- <cocoa key="title"/>
- </property>
- <property name="id" code="ID " description="The unique identifier of the window." type="integer" access="r">
- <cocoa key="uniqueID"/>
- </property>
- <property name="index" code="pidx" description="The index of the window, ordered front to back." type="integer">
- <cocoa key="orderedIndex"/>
- </property>
- <property name="bounds" code="pbnd" description="The bounding rectangle of the window." type="rectangle">
- <cocoa key="boundsAsQDRect"/>
- </property>
- <property name="closeable" code="hclb" description="Whether the window has a close box." type="boolean" access="r">
- <cocoa key="hasCloseBox"/>
- </property>
- <property name="minimizable" code="ismn" description="Whether the window can be minimized." type="boolean" access="r">
- <cocoa key="isMiniaturizable"/>
- </property>
- <property name="minimized" code="pmnd" description="Whether the window is currently minimized." type="boolean">
- <cocoa key="isMiniaturized"/>
- </property>
- <property name="resizable" code="prsz" description="Whether the window can be resized." type="boolean" access="r">
- <cocoa key="isResizable"/>
- </property>
- <property name="visible" code="pvis" description="Whether the window is currently visible." type="boolean">
- <cocoa key="isVisible"/>
- </property>
- <property name="zoomable" code="iszm" description="Whether the window can be zoomed." type="boolean" access="r">
- <cocoa key="isZoomable"/>
- </property>
- <property name="zoomed" code="pzum" description="Whether the window is currently zoomed." type="boolean">
- <cocoa key="isZoomed"/>
- </property>
- <property name="active tab" code="acTa" description="Returns the currently selected tab" type="tab" access="r">
- <cocoa key="activeTab"/>
- </property>
- <property name="mode" code="mode" description="Represents the mode of the window which can be &apos;normal&apos; or &apos;incognito&apos;, can be set only once during creation of the window." type="text">
- <cocoa key="mode"/>
- </property>
- <property name="active tab index" code="acTI" description="The index of the active tab." type="integer"/>
- <responds-to command="close">
- <cocoa method="handlesCloseScriptCommand:"/>
- </responds-to>
- </class>
- <command name="save" code="coresave" description="Save an object.">
- <direct-parameter description="the object to save, usually a document or window" type="specifier"/>
- <parameter name="in" code="kfil" description="The file in which to save the object." type="file" optional="yes">
- <cocoa key="File"/>
- </parameter>
- <parameter name="as" code="fltp" description="The file type in which to save the data. Can be &apos;only html&apos; or &apos;complete html&apos;, default is &apos;complete html&apos;." type="text" optional="yes">
- <cocoa key="FileType"/>
- </parameter>
- </command>
- <!--
- According to TN2106, 'open' should return the resulting document
- object. However, the Cocoa implementation does not do this yet.
- <result type="specifier"/>
- -->
- <command name="open" code="aevtodoc" description="Open a document.">
- <direct-parameter description="The file(s) to be opened.">
- <type type="file" list="yes"/>
- </direct-parameter>
- </command>
- <command name="close" code="coreclos" description="Close a window.">
- <cocoa class="NSCloseCommand"/>
- <direct-parameter description="the document(s) or window(s) to close." type="specifier"/>
- </command>
- <command name="quit" code="aevtquit" description="Quit the application.">
- <cocoa class="NSQuitCommand"/>
- </command>
- <command name="count" code="corecnte" description="Return the number of elements of a particular class within an object.">
- <cocoa class="NSCountCommand"/>
- <direct-parameter description="the object whose elements are to be counted" type="specifier"/>
- <parameter name="each" code="kocl" description="The class of objects to be counted." type="type" optional="yes">
- <cocoa key="ObjectClass"/>
- </parameter>
- <result description="the number of elements" type="integer"/>
- </command>
- <command name="delete" code="coredelo" description="Delete an object.">
- <cocoa class="NSDeleteCommand"/>
- <direct-parameter description="the object to delete" type="specifier"/>
- </command>
- <command name="duplicate" code="coreclon" description="Copy object(s) and put the copies at a new location.">
- <cocoa class="NSCloneCommand"/>
- <direct-parameter description="the object(s) to duplicate" type="specifier"/>
- <parameter name="to" code="insh" description="The location for the new object(s)." type="location specifier" optional="yes">
- <cocoa key="ToLocation"/>
- </parameter>
- <parameter name="with properties" code="prdt" description="Properties to be set in the new duplicated object(s)." type="record" optional="yes">
- <cocoa key="WithProperties"/>
- </parameter>
- <result description="the duplicated object(s)" type="specifier"/>
- </command>
- <command name="exists" code="coredoex" description="Verify if an object exists.">
- <cocoa class="NSExistsCommand"/>
- <direct-parameter description="the object in question" type="any"/>
- <result description="true if it exists, false if not" type="boolean"/>
- </command>
- <command name="make" code="corecrel" description="Make a new object.">
- <cocoa class="NSCreateCommand"/>
- <parameter name="new" code="kocl" description="The class of the new object." type="type">
- <cocoa key="ObjectClass"/>
- </parameter>
- <parameter name="at" code="insh" description="The location at which to insert the object." type="location specifier" optional="yes">
- <cocoa key="Location"/>
- </parameter>
- <parameter name="with data" code="data" description="The initial contents of the object." type="any" optional="yes">
- <cocoa key="ObjectData"/>
- </parameter>
- <parameter name="with properties" code="prdt" description="The initial values for properties of the object." type="record" optional="yes">
- <cocoa key="KeyDictionary"/>
- </parameter>
- <result description="to the new object" type="specifier"/>
- </command>
- <command name="move" code="coremove" description="Move object(s) to a new location.">
- <cocoa class="NSMoveCommand"/>
- <direct-parameter description="the object(s) to move" type="specifier"/>
- <parameter name="to" code="insh" description="The new location for the object(s)." type="location specifier">
- <cocoa key="ToLocation"/>
- </parameter>
- <result description="the moved object(s)" type="specifier"/>
- </command>
- <!-- NSCoreSuite doesn't define these.
- <command name="run" code="aevtoapp" description="Run an application. Most applications will open an empty, untitled window."/>
- <command name="reopen" code="aevtrapp" description="Reactivate a running application. Some applications will open a new untitled window if no window is open."/>
- -->
- <command name="print" code="aevtpdoc" description="Print an object.">
- <!-- type would be better written as "file | document". -->
- <direct-parameter description="The file(s) or document(s) to be printed." type="specifier"/>
- </command>
- <!-- "set" is supposed to be hidden. -->
- <command name="set" code="coresetd" description="Set an object&apos;s data.">
- <cocoa class="NSSetCommand"/>
- <direct-parameter type="specifier"/>
- <!-- "set" is supposed to return the fully evaluated "to" data.
- <result type="any"/>
- -->
- <parameter name="to" code="data" description="The new value." type="any">
- <cocoa key="Value"/>
- </parameter>
- </command>
- <!-- "get" is supposed to be hidden. -->
- <command name="get" code="coregetd" description="Get the data for an object.">
- <cocoa class="NSGetCommand"/>
- <direct-parameter type="specifier"/>
- <result type="any"/>
- </command>
- </suite>
- <suite name="Chromium Suite" code="CrSu" description="Common classes and commands for Chrome.">
- <class-extension description="The application&apos;s top-level scripting object." extends="application">
- <cocoa class="BrowserCrApplication"/>
- <element description="Contains the bookmarks bar and other bookmarks folder." type="bookmark folder" access="r">
- <cocoa key="bookmarkFolders"/>
- </element>
- <property name="bookmarks bar" code="ChBB" description="The bookmarks bar bookmark folder." type="bookmark folder" access="r">
- <cocoa key="bookmarksBar"/>
- </property>
- <property name="other bookmarks" code="ChOB" description="The other bookmarks bookmark folder." type="bookmark folder" access="r">
- <cocoa key="otherBookmarks"/>
- </property>
- </class-extension>
- <class name="tab" code="CrTb" description="A tab.">
- <cocoa class="TabAppleScript"/>
- <property name="id" code="ID " description="Unique ID of the tab." type="integer" access="r">
- <cocoa key="uniqueID"/>
- </property>
- <property name="title" code="pnam" description="The title of the tab." type="text" access="r"/>
- <property name="URL" code="URL " description="The url visible to the user." type="text"/>
- <property name="loading" code="ldng" description="Is loading?" type="boolean" access="r"/>
- <responds-to command="undo">
- <cocoa method="handlesUndoScriptCommand:"/>
- </responds-to>
- <responds-to command="redo">
- <cocoa method="handlesRedoScriptCommand:"/>
- </responds-to>
- <responds-to command="cut selection">
- <cocoa method="handlesCutScriptCommand:"/>
- </responds-to>
- <responds-to command="copy selection">
- <cocoa method="handlesCopyScriptCommand:"/>
- </responds-to>
- <responds-to command="paste selection">
- <cocoa method="handlesPasteScriptCommand:"/>
- </responds-to>
- <responds-to command="select all">
- <cocoa method="handlesSelectAllScriptCommand:"/>
- </responds-to>
- <responds-to command="go back">
- <cocoa method="handlesGoBackScriptCommand:"/>
- </responds-to>
- <responds-to command="go forward">
- <cocoa method="handlesGoForwardScriptCommand:"/>
- </responds-to>
- <responds-to command="reload">
- <cocoa method="handlesReloadScriptCommand:"/>
- </responds-to>
- <responds-to command="stop">
- <cocoa method="handlesStopScriptCommand:"/>
- </responds-to>
- <responds-to command="print">
- <cocoa method="handlesPrintScriptCommand:"/>
- </responds-to>
- <responds-to command="view source">
- <cocoa method="handlesViewSourceScriptCommand:"/>
- </responds-to>
- <responds-to command="save">
- <cocoa method="handlesSaveScriptCommand:"/>
- </responds-to>
- <responds-to command="execute">
- <cocoa method="handlesExecuteJavascriptScriptCommand:"/>
- </responds-to>
- </class>
- <class name="bookmark folder" code="CrBF" description="A bookmarks folder that contains other bookmarks folder and bookmark items.">
- <cocoa class="BookmarkFolderAppleScript"/>
- <element description="The bookmark folders present within." type="bookmark folder">
- <cocoa key="bookmarkFolders"/>
- </element>
- <element description="The bookmarks present within." type="bookmark item">
- <cocoa key="bookmarkItems"/>
- </element>
- <property name="id" code="ID " description="Unique ID of the bookmark folder." type="number" access="r">
- <cocoa key="uniqueID"/>
- </property>
- <property name="title" code="pnam" description="The title of the folder." type="text"/>
- <property name="index" code="indx" description="Returns the index with respect to its parent bookmark folder" type="number" access="r"/>
- </class>
- <class name="bookmark item" code="CrBI" description="An item consists of an URL and the title of a bookmark">
- <cocoa class="BookmarkItemAppleScript"/>
- <property name="id" code="ID " description="Unique ID of the bookmark item." type="integer" access="r">
- <cocoa key="uniqueID"/>
- </property>
- <property name="title" code="pnam" description="The title of the bookmark item." type="text"/>
- <property name="URL" code="URL " description="The URL of the bookmark." type="text"/>
- <property name="index" code="indx" description="Returns the index with respect to its parent bookmark folder" type="number" access="r"/>
- </class>
- <command name="reload" code="CrSuRlod" description="Reload a tab.">
- <direct-parameter description="The tab to execute the command in." type="specifier"/>
- </command>
- <command name="go back" code="CrSuBack" description="Go Back (If Possible).">
- <direct-parameter description="The tab to execute the command in." type="specifier"/>
- </command>
- <command name="go forward" code="CrSuFwd " description="Go Forward (If Possible).">
- <direct-parameter description="The tab to execute the command in." type="specifier"/>
- </command>
- <command name="select all" code="CrSuSlAl" description="Select all.">
- <direct-parameter description="The tab to execute the command in." type="specifier"/>
- </command>
- <command name="cut selection" code="CrSuCut " description="Cut selected text (If Possible).">
- <direct-parameter description="The tab to execute the command in." type="specifier"/>
- </command>
- <command name="copy selection" code="CrSuCop " description="Copy text.">
- <direct-parameter description="The tab to execute the command in." type="specifier"/>
- </command>
- <command name="paste selection" code="CrSuPast" description="Paste text (If Possible).">
- <direct-parameter description="The tab to execute the command in." type="specifier"/>
- </command>
- <command name="undo" code="CrSuUndo" description="Undo the last change.">
- <direct-parameter description="The tab to execute the command in." type="specifier"/>
- </command>
- <command name="redo" code="CrSuRedo" description="Redo the last change.">
- <direct-parameter description="The tab to execute the command in." type="specifier"/>
- </command>
- <command name="stop" code="CrSustop" description="Stop the current tab from loading.">
- <direct-parameter description="The tab to execute the command in." type="specifier"/>
- </command>
- <command name="view source" code="CrSuVSrc" description="View the HTML source of the tab.">
- <direct-parameter description="The tab to execute the command in." type="specifier"/>
- </command>
- <command name="execute" code="CrSuExJa" description="Execute a piece of javascript.">
- <direct-parameter description="The tab to execute the command in." type="specifier"/>
- <parameter name="javascript" code="JvSc" description="The javascript code to execute." type="text">
- <cocoa key="javascript"/>
- </parameter>
- <result type="any"/>
- </command>
- </suite>
-</dictionary> \ No newline at end of file
diff --git a/chrome/browser/cocoa/applescript/tab_applescript.h b/chrome/browser/cocoa/applescript/tab_applescript.h
deleted file mode 100644
index 28ba1fe..0000000
--- a/chrome/browser/cocoa/applescript/tab_applescript.h
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (c) 2010 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_COCOA_APPLESCRIPT_TAB_APPLESCRIPT_H_
-#define CHROME_BROWSER_COCOA_APPLESCRIPT_TAB_APPLESCRIPT_H_
-
-#import <Cocoa/Cocoa.h>
-
-#import "chrome/browser/cocoa/applescript/element_applescript.h"
-
-class TabContents;
-
-// Represents a tab scriptable item in applescript.
-@interface TabAppleScript : ElementAppleScript {
- @private
- TabContents* tabContents_; // weak.
- // Contains the temporary URL when a user creates a new folder/item with
- // url specified like
- // |make new tab with properties {url:"http://google.com"}|.
- NSString* tempURL_;
-}
-
-// Doesn't actually create the tab here but just assigns the ID, tab is created
-// when it calls insertInTabs: of a particular window, it is used in cases
-// where user assigns a tab to a variable like |set var to make new tab|.
-- (id)init;
-
-// Does not create a new tab but uses an existing one.
-- (id)initWithTabContent:(TabContents*)aTabContent;
-
-// Assigns a tab, sets its unique ID and also copies temporary values.
-- (void)setTabContent:(TabContents*)aTabContent;
-
-// Return the URL currently visible to the user in the location bar.
-- (NSString*)URL;
-
-// Sets the URL, returns an error if it is invalid.
-- (void)setURL:(NSString*)aURL;
-
-// The title of the tab.
-- (NSString*)title;
-
-// Is the tab loading any resource?
-- (NSNumber*)loading;
-
-// Standard user commands.
-- (void)handlesUndoScriptCommand:(NSScriptCommand*)command;
-- (void)handlesRedoScriptCommand:(NSScriptCommand*)command;
-
-// Edit operations on the page.
-- (void)handlesCutScriptCommand:(NSScriptCommand*)command;
-- (void)handlesCopyScriptCommand:(NSScriptCommand*)command;
-- (void)handlesPasteScriptCommand:(NSScriptCommand*)command;
-
-// Selects all contents on the page.
-- (void)handlesSelectAllScriptCommand:(NSScriptCommand*)command;
-
-// Navigation operations.
-- (void)handlesGoBackScriptCommand:(NSScriptCommand*)command;
-- (void)handlesGoForwardScriptCommand:(NSScriptCommand*)command;
-- (void)handlesReloadScriptCommand:(NSScriptCommand*)command;
-- (void)handlesStopScriptCommand:(NSScriptCommand*)command;
-
-// Used to print a tab.
-- (void)handlesPrintScriptCommand:(NSScriptCommand*)command;
-
-// Used to save a tab, if no file is specified, prompts the user to enter it.
-- (void)handlesSaveScriptCommand:(NSScriptCommand*)command;
-
-// Displays the HTML of the tab in a new tab.
-- (void)handlesViewSourceScriptCommand:(NSScriptCommand*)command;
-
-// Executes a piece of javascript in the tab.
-- (id)handlesExecuteJavascriptScriptCommand:(NSScriptCommand*)command;
-
-@end
-
-#endif// CHROME_BROWSER_COCOA_APPLESCRIPT_TAB_APPLESCRIPT_H_
diff --git a/chrome/browser/cocoa/applescript/tab_applescript.mm b/chrome/browser/cocoa/applescript/tab_applescript.mm
deleted file mode 100644
index ee4af12..0000000
--- a/chrome/browser/cocoa/applescript/tab_applescript.mm
+++ /dev/null
@@ -1,296 +0,0 @@
-// Copyright (c) 2010 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/cocoa/applescript/tab_applescript.h"
-
-#include "base/file_path.h"
-#include "base/logging.h"
-#import "base/scoped_nsobject.h"
-#include "base/sys_string_conversions.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/browser/cocoa/applescript/error_applescript.h"
-#include "chrome/browser/download/save_package.h"
-#include "chrome/browser/renderer_host/render_view_host.h"
-#include "chrome/browser/tab_contents/navigation_controller.h"
-#include "chrome/browser/tab_contents/navigation_entry.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/sessions/session_id.h"
-#include "chrome/common/url_constants.h"
-#include "googleurl/src/gurl.h"
-
-@interface TabAppleScript()
-@property (nonatomic, copy) NSString* tempURL;
-@end
-
-@implementation TabAppleScript
-
-@synthesize tempURL = tempURL_;
-
-- (id)init {
- if ((self = [super init])) {
- SessionID session;
- SessionID::id_type futureSessionIDOfTab = session.id() + 1;
- // Holds the SessionID that the new tab is going to get.
- scoped_nsobject<NSNumber> numID(
- [[NSNumber alloc]
- initWithInt:futureSessionIDOfTab]);
- [self setUniqueID:numID];
- [self setTempURL:@""];
- }
- return self;
-}
-
-- (void)dealloc {
- [tempURL_ release];
- [super dealloc];
-}
-
-- (id)initWithTabContent:(TabContents*)aTabContent {
- if (!aTabContent) {
- [self release];
- return nil;
- }
-
- if ((self = [super init])) {
- // It is safe to be weak, if a tab goes away (eg user closing a tab)
- // the applescript runtime calls tabs in AppleScriptWindow and this
- // particular tab is never returned.
- tabContents_ = aTabContent;
- scoped_nsobject<NSNumber> numID(
- [[NSNumber alloc]
- initWithInt:tabContents_->controller().session_id().id()]);
- [self setUniqueID:numID];
- }
- return self;
-}
-
-- (void)setTabContent:(TabContents*)aTabContent {
- DCHECK(aTabContent);
- // It is safe to be weak, if a tab goes away (eg user closing a tab)
- // the applescript runtime calls tabs in AppleScriptWindow and this
- // particular tab is never returned.
- tabContents_ = aTabContent;
- scoped_nsobject<NSNumber> numID(
- [[NSNumber alloc]
- initWithInt:tabContents_->controller().session_id().id()]);
- [self setUniqueID:numID];
-
- [self setURL:[self tempURL]];
-}
-
-- (NSString*)URL {
- if (!tabContents_) {
- return nil;
- }
-
- NavigationEntry* entry = tabContents_->controller().GetActiveEntry();
- if (!entry) {
- return nil;
- }
- const GURL& url = entry->virtual_url();
- return base::SysUTF8ToNSString(url.spec());
-}
-
-- (void)setURL:(NSString*)aURL {
- // If a scripter sets a URL before the node is added save it at a temporary
- // location.
- if (!tabContents_) {
- [self setTempURL:aURL];
- return;
- }
-
- GURL url(base::SysNSStringToUTF8(aURL));
- // check for valid url.
- if (!url.is_empty() && !url.is_valid()) {
- AppleScript::SetError(AppleScript::errInvalidURL);
- return;
- }
-
- NavigationEntry* entry = tabContents_->controller().GetActiveEntry();
- if (!entry)
- return;
-
- const GURL& previousURL = entry->virtual_url();
- tabContents_->OpenURL(url,
- previousURL,
- CURRENT_TAB,
- PageTransition::TYPED);
-}
-
-- (NSString*)title {
- NavigationEntry* entry = tabContents_->controller().GetActiveEntry();
- if (!entry)
- return nil;
-
- std::wstring title;
- if (entry != NULL) {
- title = UTF16ToWideHack(entry->title());
- }
-
- return base::SysWideToNSString(title);
-}
-
-- (NSNumber*)loading {
- BOOL loadingValue = tabContents_->is_loading() ? YES : NO;
- return [NSNumber numberWithBool:loadingValue];
-}
-
-- (void)handlesUndoScriptCommand:(NSScriptCommand*)command {
- RenderViewHost* view = tabContents_->render_view_host();
- if (!view) {
- NOTREACHED();
- return;
- }
-
- view->Undo();
-}
-
-- (void)handlesRedoScriptCommand:(NSScriptCommand*)command {
- RenderViewHost* view = tabContents_->render_view_host();
- if (!view) {
- NOTREACHED();
- return;
- }
-
- view->Redo();
-}
-
-- (void)handlesCutScriptCommand:(NSScriptCommand*)command {
- RenderViewHost* view = tabContents_->render_view_host();
- if (!view) {
- NOTREACHED();
- return;
- }
-
- view->Cut();
-}
-
-- (void)handlesCopyScriptCommand:(NSScriptCommand*)command {
- RenderViewHost* view = tabContents_->render_view_host();
- if (!view) {
- NOTREACHED();
- return;
- }
-
- view->Copy();
-}
-
-- (void)handlesPasteScriptCommand:(NSScriptCommand*)command {
- RenderViewHost* view = tabContents_->render_view_host();
- if (!view) {
- NOTREACHED();
- return;
- }
-
- view->Paste();
-}
-
-- (void)handlesSelectAllScriptCommand:(NSScriptCommand*)command {
- RenderViewHost* view = tabContents_->render_view_host();
- if (!view) {
- NOTREACHED();
- return;
- }
-
- view->SelectAll();
-}
-
-- (void)handlesGoBackScriptCommand:(NSScriptCommand*)command {
- NavigationController& navigationController = tabContents_->controller();
- if (navigationController.CanGoBack())
- navigationController.GoBack();
-}
-
-- (void)handlesGoForwardScriptCommand:(NSScriptCommand*)command {
- NavigationController& navigationController = tabContents_->controller();
- if (navigationController.CanGoForward())
- navigationController.GoForward();
-}
-
-- (void)handlesReloadScriptCommand:(NSScriptCommand*)command {
- NavigationController& navigationController = tabContents_->controller();
- const bool checkForRepost = true;
- navigationController.Reload(checkForRepost);
-}
-
-- (void)handlesStopScriptCommand:(NSScriptCommand*)command {
- RenderViewHost* view = tabContents_->render_view_host();
- if (!view) {
- // We tolerate Stop being called even before a view has been created.
- // So just log a warning instead of a NOTREACHED().
- DLOG(WARNING) << "Stop: no view for handle ";
- return;
- }
-
- view->Stop();
-}
-
-- (void)handlesPrintScriptCommand:(NSScriptCommand*)command {
- bool initiateStatus = tabContents_->PrintNow();
- if (initiateStatus == false) {
- AppleScript::SetError(AppleScript::errInitiatePrinting);
- }
-}
-
-- (void)handlesSaveScriptCommand:(NSScriptCommand*)command {
- NSDictionary* dictionary = [command evaluatedArguments];
-
- NSURL* fileURL = [dictionary objectForKey:@"File"];
- // Scripter has not specifed the location at which to save, so we prompt for
- // it.
- if (!fileURL) {
- tabContents_->OnSavePage();
- return;
- }
-
- FilePath mainFile(base::SysNSStringToUTF8([fileURL path]));
- // We create a directory path at the folder within which the file exists.
- // Eg. if main_file = '/Users/Foo/Documents/Google.html'
- // then directory_path = '/Users/Foo/Documents/Google_files/'.
- FilePath directoryPath = mainFile.RemoveExtension();
- directoryPath = directoryPath.InsertBeforeExtension(std::string("_files/"));
-
- NSString* saveType = [dictionary objectForKey:@"FileType"];
-
- SavePackage::SavePackageType savePackageType =
- SavePackage::SAVE_AS_COMPLETE_HTML;
- if (saveType) {
- if ([saveType isEqualToString:@"only html"]) {
- savePackageType = SavePackage::SAVE_AS_ONLY_HTML;
- } else if ([saveType isEqualToString:@"complete html"]) {
- savePackageType = SavePackage::SAVE_AS_COMPLETE_HTML;
- } else {
- AppleScript::SetError(AppleScript::errInvalidSaveType);
- return;
- }
- }
-
- tabContents_->SavePage(mainFile, directoryPath, savePackageType);
-}
-
-
-- (void)handlesViewSourceScriptCommand:(NSScriptCommand*)command {
- NavigationEntry* entry = tabContents_->controller().GetLastCommittedEntry();
- if (entry) {
- tabContents_->OpenURL(GURL(chrome::kViewSourceScheme + std::string(":") +
- entry->url().spec()), GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
- }
-}
-
-- (id)handlesExecuteJavascriptScriptCommand:(NSScriptCommand*)command {
- RenderViewHost* view = tabContents_->render_view_host();
- if (!view) {
- NOTREACHED();
- return nil;
- }
-
- std::wstring script = base::SysNSStringToWide(
- [[command evaluatedArguments] objectForKey:@"javascript"]);
- view->ExecuteJavascriptInWebFrame(L"", script);
-
- // TODO(Shreyas): Figure out a way to get the response back.
- return nil;
-}
-
-@end
diff --git a/chrome/browser/cocoa/applescript/window_applescript.h b/chrome/browser/cocoa/applescript/window_applescript.h
deleted file mode 100644
index 5bda32f..0000000
--- a/chrome/browser/cocoa/applescript/window_applescript.h
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright (c) 2010 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_COCOA_APPLESCRIPT_WINDOW_APPLESCRIPT_H_
-#define CHROME_BROWSER_COCOA_APPLESCRIPT_WINDOW_APPLESCRIPT_H_
-
-#import <Cocoa/Cocoa.h>
-
-#import "chrome/browser/cocoa/applescript/element_applescript.h"
-
-class Browser;
-class Profile;
-@class TabAppleScript;
-
-// Represents a window class.
-@interface WindowAppleScript : ElementAppleScript {
- @private
- Browser* browser_; // weak.
-}
-
-// Creates a new window, returns nil if there is an error.
-- (id)init;
-
-// Creates a new window with a particular profile.
-- (id)initWithProfile:(Profile*)aProfile;
-
-// Does not create a new window but uses an existing one.
-- (id)initWithBrowser:(Browser*)aBrowser;
-
-// Sets and gets the index of the currently selected tab.
-- (NSNumber*)activeTabIndex;
-- (void)setActiveTabIndex:(NSNumber*)anActiveTabIndex;
-
-// Mode refers to whether a window is a normal window or an incognito window
-// it can be set only once while creating the window.
-- (NSString*)mode;
-- (void)setMode:(NSString*)theMode;
-
-// Returns the currently selected tab.
-- (TabAppleScript*)activeTab;
-
-// Tab manipulation functions.
-// The tabs inside the window.
-// Returns |TabAppleScript*| of all the tabs contained
-// within this particular folder.
-- (NSArray*)tabs;
-
-// Insert a tab at the end.
-- (void)insertInTabs:(TabAppleScript*)aTab;
-
-// Insert a tab at some position in the list.
-// Called by applescript which takes care of bounds checking, make sure of it
-// before calling directly.
-- (void)insertInTabs:(TabAppleScript*)aTab atIndex:(int)index;
-
-// Remove a window from the list.
-// Called by applescript which takes care of bounds checking, make sure of it
-// before calling directly.
-- (void)removeFromTabsAtIndex:(int)index;
-
-// Set the index of a window.
-- (void)setOrderedIndex:(NSNumber*)anIndex;
-
-// Used to sort windows by index.
-- (NSComparisonResult)windowComparator:(WindowAppleScript*)otherWindow;
-
-// For standard window functions like zoomable, bounds etc, we dont handle it
-// but instead pass it onto the NSWindow associated with the window.
-- (id)valueForUndefinedKey:(NSString*)key;
-- (void)setValue:(id)value forUndefinedKey:(NSString*)key;
-
-// Used to close window.
-- (void)handlesCloseScriptCommand:(NSCloseCommand*)command;
-
-// The index of the window, windows are ordered front to back.
-- (NSNumber*)orderedIndex;
-
-@end
-
-#endif // CHROME_BROWSER_COCOA_APPLESCRIPT_WINDOW_APPLESCRIPT_H_
diff --git a/chrome/browser/cocoa/applescript/window_applescript.mm b/chrome/browser/cocoa/applescript/window_applescript.mm
deleted file mode 100644
index 0f279ac..0000000
--- a/chrome/browser/cocoa/applescript/window_applescript.mm
+++ /dev/null
@@ -1,246 +0,0 @@
-// Copyright (c) 2010 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/cocoa/applescript/window_applescript.h"
-
-#include "base/logging.h"
-#import "base/scoped_nsobject.h"
-#include "base/scoped_ptr.h"
-#include "base/time.h"
-#import "chrome/browser/app_controller_mac.h"
-#import "chrome/browser/chrome_browser_application_mac.h"
-#include "chrome/browser/cocoa/applescript/constants_applescript.h"
-#include "chrome/browser/cocoa/applescript/error_applescript.h"
-#import "chrome/browser/cocoa/applescript/tab_applescript.h"
-#include "chrome/browser/profile.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/tab_contents_wrapper.h"
-#include "chrome/browser/tabs/tab_strip_model.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_list.h"
-#include "chrome/browser/ui/browser_navigator.h"
-#include "chrome/browser/ui/browser_window.h"
-#include "chrome/common/url_constants.h"
-
-@interface WindowAppleScript(WindowAppleScriptPrivateMethods)
-// The NSWindow that corresponds to this window.
-- (NSWindow*)nativeHandle;
-@end
-
-@implementation WindowAppleScript
-
-- (id)init {
- // Check which mode to open a new window.
- NSScriptCommand* command = [NSScriptCommand currentCommand];
- NSString* mode = [[[command evaluatedArguments]
- objectForKey:@"KeyDictionary"] objectForKey:@"mode"];
- AppController* appDelegate = [NSApp delegate];
-
- Profile* defaultProfile = [appDelegate defaultProfile];
-
- if (!defaultProfile) {
- AppleScript::SetError(AppleScript::errGetProfile);
- return nil;
- }
-
- Profile* profile;
- if ([mode isEqualToString:AppleScript::kIncognitoWindowMode]) {
- profile = defaultProfile->GetOffTheRecordProfile();
- }
- else if ([mode isEqualToString:AppleScript::kNormalWindowMode] || !mode) {
- profile = defaultProfile;
- } else {
- // Mode cannot be anything else
- AppleScript::SetError(AppleScript::errInvalidMode);
- return nil;
- }
- // Set the mode to nil, to ensure that it is not set once more.
- [[[command evaluatedArguments] objectForKey:@"KeyDictionary"]
- setValue:nil forKey:@"mode"];
- return [self initWithProfile:profile];
-}
-
-- (id)initWithProfile:(Profile*)aProfile {
- if (!aProfile) {
- [self release];
- return nil;
- }
-
- if ((self = [super init])) {
- browser_ = Browser::Create(aProfile);
- browser_->NewTab();
- browser_->window()->Show();
- scoped_nsobject<NSNumber> numID(
- [[NSNumber alloc] initWithInt:browser_->session_id().id()]);
- [self setUniqueID:numID];
- }
- return self;
-}
-
-- (id)initWithBrowser:(Browser*)aBrowser {
- if (!aBrowser) {
- [self release];
- return nil;
- }
-
- if ((self = [super init])) {
- // It is safe to be weak, if a window goes away (eg user closing a window)
- // the applescript runtime calls appleScriptWindows in
- // BrowserCrApplication and this particular window is never returned.
- browser_ = aBrowser;
- scoped_nsobject<NSNumber> numID(
- [[NSNumber alloc] initWithInt:browser_->session_id().id()]);
- [self setUniqueID:numID];
- }
- return self;
-}
-
-- (NSWindow*)nativeHandle {
- // window() can be NULL during startup.
- if (browser_->window())
- return browser_->window()->GetNativeHandle();
- return nil;
-}
-
-- (NSNumber*)activeTabIndex {
- // Note: applescript is 1-based, that is lists begin with index 1.
- int activeTabIndex = browser_->selected_index() + 1;
- if (!activeTabIndex) {
- return nil;
- }
- return [NSNumber numberWithInt:activeTabIndex];
-}
-
-- (void)setActiveTabIndex:(NSNumber*)anActiveTabIndex {
- // Note: applescript is 1-based, that is lists begin with index 1.
- int atIndex = [anActiveTabIndex intValue] - 1;
- if (atIndex >= 0 && atIndex < browser_->tab_count())
- browser_->SelectTabContentsAt(atIndex, true);
- else
- AppleScript::SetError(AppleScript::errInvalidTabIndex);
-}
-
-- (NSString*)mode {
- Profile* profile = browser_->profile();
- if (profile->IsOffTheRecord())
- return AppleScript::kIncognitoWindowMode;
- return AppleScript::kNormalWindowMode;
-}
-
-- (void)setMode:(NSString*)theMode {
- // cannot set mode after window is created.
- if (theMode) {
- AppleScript::SetError(AppleScript::errSetMode);
- }
-}
-
-- (TabAppleScript*)activeTab {
- TabAppleScript* currentTab = [[[TabAppleScript alloc]
- initWithTabContent:browser_->GetSelectedTabContents()] autorelease];
- [currentTab setContainer:self
- property:AppleScript::kTabsProperty];
- return currentTab;
-}
-
-- (NSArray*)tabs {
- NSMutableArray* tabs = [NSMutableArray
- arrayWithCapacity:browser_->tab_count()];
-
- for (int i = 0; i < browser_->tab_count(); ++i) {
- // Check to see if tab is closing.
- if (browser_->GetTabContentsAt(i)->is_being_destroyed()) {
- continue;
- }
-
- scoped_nsobject<TabAppleScript> tab(
- [[TabAppleScript alloc]
- initWithTabContent:(browser_->GetTabContentsAt(i))]);
- [tab setContainer:self
- property:AppleScript::kTabsProperty];
- [tabs addObject:tab];
- }
- return tabs;
-}
-
-- (void)insertInTabs:(TabAppleScript*)aTab {
- // This method gets called when a new tab is created so
- // the container and property are set here.
- [aTab setContainer:self
- property:AppleScript::kTabsProperty];
-
- // Set how long it takes a tab to be created.
- base::TimeTicks newTabStartTime = base::TimeTicks::Now();
- TabContentsWrapper* contents =
- browser_->AddSelectedTabWithURL(GURL(chrome::kChromeUINewTabURL),
- PageTransition::TYPED);
- contents->tab_contents()->set_new_tab_start_time(newTabStartTime);
- [aTab setTabContent:contents->tab_contents()];
-}
-
-- (void)insertInTabs:(TabAppleScript*)aTab atIndex:(int)index {
- // This method gets called when a new tab is created so
- // This method gets called when a new tab is created so
- // the container and property are set here.
- [aTab setContainer:self
- property:AppleScript::kTabsProperty];
-
- // Set how long it takes a tab to be created.
- base::TimeTicks newTabStartTime = base::TimeTicks::Now();
- browser::NavigateParams params(browser_,
- GURL(chrome::kChromeUINewTabURL),
- PageTransition::TYPED);
- params.disposition = NEW_FOREGROUND_TAB;
- params.tabstrip_index = index;
- browser::Navigate(&params);
- params.target_contents->tab_contents()->set_new_tab_start_time(
- newTabStartTime);
-
- [aTab setTabContent:params.target_contents->tab_contents()];
-}
-
-- (void)removeFromTabsAtIndex:(int)index {
- browser_->tabstrip_model()->DetachTabContentsAt(index);
-}
-
-- (NSNumber*)orderedIndex{
- return [NSNumber numberWithInt:[[self nativeHandle] orderedIndex]];
-}
-
-- (void)setOrderedIndex:(NSNumber*)anIndex {
- int index = [anIndex intValue] - 1;
- if (index < 0 || index >= (int)BrowserList::size()) {
- AppleScript::SetError(AppleScript::errWrongIndex);
- return;
- }
- [[self nativeHandle] setOrderedIndex:index];
-}
-
-- (NSComparisonResult)windowComparator:(WindowAppleScript*)otherWindow {
- int thisIndex = [[self orderedIndex] intValue];
- int otherIndex = [[otherWindow orderedIndex] intValue];
- if (thisIndex < otherIndex)
- return NSOrderedAscending;
- else if (thisIndex > otherIndex)
- return NSOrderedDescending;
- // Indexes can never be same.
- NOTREACHED();
- return NSOrderedSame;
-}
-
-// Get and set values from the associated NSWindow.
-- (id)valueForUndefinedKey:(NSString*)key {
- return [[self nativeHandle] valueForKey:key];
-}
-
-- (void)setValue:(id)value forUndefinedKey:(NSString*)key {
- [[self nativeHandle] setValue:(id)value forKey:key];
-}
-
-- (void)handlesCloseScriptCommand:(NSCloseCommand*)command {
- // window() can be NULL during startup.
- if (browser_->window())
- browser_->window()->Close();
-}
-
-@end
diff --git a/chrome/browser/cocoa/applescript/window_applescript_test.mm b/chrome/browser/cocoa/applescript/window_applescript_test.mm
deleted file mode 100644
index 6d0a9d3..0000000
--- a/chrome/browser/cocoa/applescript/window_applescript_test.mm
+++ /dev/null
@@ -1,178 +0,0 @@
-// Copyright (c) 2010 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>
-
-#import "base/scoped_nsobject.h"
-#include "base/sys_string_conversions.h"
-#import "chrome/browser/app_controller_mac.h"
-#import "chrome/browser/chrome_browser_application_mac.h"
-#import "chrome/browser/cocoa/applescript/constants_applescript.h"
-#import "chrome/browser/cocoa/applescript/error_applescript.h"
-#import "chrome/browser/cocoa/applescript/tab_applescript.h"
-#import "chrome/browser/cocoa/applescript/window_applescript.h"
-#include "chrome/browser/profile.h"
-#include "chrome/test/in_process_browser_test.h"
-#include "googleurl/src/gurl.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#import "testing/gtest_mac.h"
-
-typedef InProcessBrowserTest WindowAppleScriptTest;
-
-// Create a window in default/normal mode.
-IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, DefaultCreation) {
- scoped_nsobject<WindowAppleScript> aWindow(
- [[WindowAppleScript alloc] init]);
- EXPECT_TRUE(aWindow.get());
- NSString* mode = [aWindow.get() mode];
- EXPECT_NSEQ(AppleScript::kNormalWindowMode,
- mode);
-}
-
-// Create a window with a |NULL profile|.
-IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, CreationWithNoProfile) {
- scoped_nsobject<WindowAppleScript> aWindow(
- [[WindowAppleScript alloc] initWithProfile:NULL]);
- EXPECT_FALSE(aWindow.get());
-}
-
-// Create a window with a particular profile.
-IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, CreationWithProfile) {
- Profile* defaultProfile = [[NSApp delegate] defaultProfile];
- scoped_nsobject<WindowAppleScript> aWindow(
- [[WindowAppleScript alloc] initWithProfile:defaultProfile]);
- EXPECT_TRUE(aWindow.get());
- EXPECT_TRUE([aWindow.get() uniqueID]);
-}
-
-// Create a window with no |Browser*|.
-IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, CreationWithNoBrowser) {
- scoped_nsobject<WindowAppleScript> aWindow(
- [[WindowAppleScript alloc] initWithBrowser:NULL]);
- EXPECT_FALSE(aWindow.get());
-}
-
-// Create a window with |Browser*| already present.
-IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, CreationWithBrowser) {
- scoped_nsobject<WindowAppleScript> aWindow(
- [[WindowAppleScript alloc] initWithBrowser:browser()]);
- EXPECT_TRUE(aWindow.get());
- EXPECT_TRUE([aWindow.get() uniqueID]);
-}
-
-// Tabs within the window.
-IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, Tabs) {
- scoped_nsobject<WindowAppleScript> aWindow(
- [[WindowAppleScript alloc] initWithBrowser:browser()]);
- NSArray* tabs = [aWindow.get() tabs];
- EXPECT_EQ(1U, [tabs count]);
- TabAppleScript* tab1 = [tabs objectAtIndex:0];
- EXPECT_EQ([tab1 container], aWindow.get());
- EXPECT_NSEQ(AppleScript::kTabsProperty,
- [tab1 containerProperty]);
-}
-
-// Insert a new tab.
-IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, InsertTab) {
- // Emulate what applescript would do when creating a new tab.
- // Emulates a script like |set var to make new tab with
- // properties URL:"http://google.com"}|.
- scoped_nsobject<TabAppleScript> aTab([[TabAppleScript alloc] init]);
- scoped_nsobject<NSNumber> var([[aTab.get() uniqueID] copy]);
- [aTab.get() setURL:@"http://google.com"];
- scoped_nsobject<WindowAppleScript> aWindow(
- [[WindowAppleScript alloc] initWithBrowser:browser()]);
- [aWindow.get() insertInTabs:aTab.get()];
-
- // Represents the tab after it is inserted.
- TabAppleScript* tab = [[aWindow.get() tabs] objectAtIndex:1];
- EXPECT_EQ(GURL("http://google.com"),
- GURL(base::SysNSStringToUTF8([tab URL])));
- EXPECT_EQ([tab container], aWindow.get());
- EXPECT_NSEQ(AppleScript::kTabsProperty,
- [tab containerProperty]);
- EXPECT_NSEQ(var.get(), [tab uniqueID]);
-}
-
-// Insert a new tab at a particular position
-IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, InsertTabAtPosition) {
- // Emulate what applescript would do when creating a new tab.
- // Emulates a script like |set var to make new tab with
- // properties URL:"http://google.com"} at before tab 1|.
- scoped_nsobject<TabAppleScript> aTab([[TabAppleScript alloc] init]);
- scoped_nsobject<NSNumber> var([[aTab.get() uniqueID] copy]);
- [aTab.get() setURL:@"http://google.com"];
- scoped_nsobject<WindowAppleScript> aWindow(
- [[WindowAppleScript alloc] initWithBrowser:browser()]);
- [aWindow.get() insertInTabs:aTab.get() atIndex:0];
-
- // Represents the tab after it is inserted.
- TabAppleScript* tab = [[aWindow.get() tabs] objectAtIndex:0];
- EXPECT_EQ(GURL("http://google.com"),
- GURL(base::SysNSStringToUTF8([tab URL])));
- EXPECT_EQ([tab container], aWindow.get());
- EXPECT_NSEQ(AppleScript::kTabsProperty, [tab containerProperty]);
- EXPECT_NSEQ(var.get(), [tab uniqueID]);
-}
-
-// Inserting and deleting tabs.
-IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, InsertAndDeleteTabs) {
- scoped_nsobject<WindowAppleScript> aWindow(
- [[WindowAppleScript alloc] initWithBrowser:browser()]);
- scoped_nsobject<TabAppleScript> aTab;
- int count;
- for (int i = 0; i < 5; ++i) {
- for (int j = 0; j < 3; ++j) {
- aTab.reset([[TabAppleScript alloc] init]);
- [aWindow.get() insertInTabs:aTab.get()];
- }
- count = 3 * i + 4;
- EXPECT_EQ((int)[[aWindow.get() tabs] count], count);
- }
-
- count = (int)[[aWindow.get() tabs] count];
- for (int i = 0; i < 5; ++i) {
- for(int j = 0; j < 3; ++j) {
- [aWindow.get() removeFromTabsAtIndex:0];
- }
- count = count - 3;
- EXPECT_EQ((int)[[aWindow.get() tabs] count], count);
- }
-}
-
-// Getting and setting values from the NSWindow.
-IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, NSWindowTest) {
- scoped_nsobject<WindowAppleScript> aWindow(
- [[WindowAppleScript alloc] initWithBrowser:browser()]);
- [aWindow.get() setValue:[NSNumber numberWithBool:YES]
- forKey:@"isMiniaturized"];
- EXPECT_TRUE([[aWindow.get() valueForKey:@"isMiniaturized"] boolValue]);
- [aWindow.get() setValue:[NSNumber numberWithBool:NO]
- forKey:@"isMiniaturized"];
- EXPECT_FALSE([[aWindow.get() valueForKey:@"isMiniaturized"] boolValue]);
-}
-
-// Getting and setting the active tab.
-IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, ActiveTab) {
- scoped_nsobject<WindowAppleScript> aWindow(
- [[WindowAppleScript alloc] initWithBrowser:browser()]);
- scoped_nsobject<TabAppleScript> aTab([[TabAppleScript alloc] init]);
- [aWindow.get() insertInTabs:aTab.get()];
- [aWindow.get() setActiveTabIndex:[NSNumber numberWithInt:2]];
- EXPECT_EQ(2, [[aWindow.get() activeTabIndex] intValue]);
- TabAppleScript* tab2 = [[aWindow.get() tabs] objectAtIndex:1];
- EXPECT_NSEQ([[aWindow.get() activeTab] uniqueID],
- [tab2 uniqueID]);
-}
-
-// Order of windows.
-IN_PROC_BROWSER_TEST_F(WindowAppleScriptTest, WindowOrder) {
- scoped_nsobject<WindowAppleScript> window2(
- [[WindowAppleScript alloc] initWithBrowser:browser()]);
- scoped_nsobject<WindowAppleScript> window1(
- [[WindowAppleScript alloc] init]);
- EXPECT_EQ([window1.get() windowComparator:window2.get()], NSOrderedAscending);
- EXPECT_EQ([window2.get() windowComparator:window1.get()],
- NSOrderedDescending);
-}