Use Chrome like a pro

Thursday, September 30, 2010 at 10:26 AM

Two months ago, Chrome team members shared a list of their favorite extensions on the Official Google blog. This time around, we asked Mac aficionados on the Chrome team to share with us the extensions they like the most. Below is a list of their favorite extensions.

  • Google Voice - Make calls, send SMS, preview inbox and get notified of new messages right in your browser (US only).

  • Send from Gmail - Makes Gmail your default email application and provides a button to compose a Gmail message to quickly share a link via email.

  • iReader - View news stories and other articles in a very easy to read, clutter-free, scrollable display.

  • Google Dictionary - View definitions easily as you browse the web, similar to using ⌘-Option-D in other Mac applications.

  • delicious bookmarks - Integrate your bookmarks with Google Chrome with the official Chrome extension for Delicious, the world's leading social bookmarking service.

  • Instachrome - Collect articles from around the Internet to read them on the web with Instapaper.


These are just a few extensions to help enhance your web browsing experience and address the most requested features. If you don’t have Google Chrome yet, you can download it here. There are more than 7,000 extensions to choose from in our Google Chrome Extensions gallery, so you’ll be sure to find the right extensions for you.

Posted by Mike Pinkerton, Staff Software Engineer

An HTTP Fetcher Class for Mac OS X and iOS Apps

Wednesday, September 15, 2010 at 2:56 PM

By Greg Robbins, Software Engineer

(Editor's note: Today's blog post is another cool one for programmers in the audience. Non-developer readers, thanks for bearing with us.)

Mac OS X and iOS provide developers with a high-level class, NSURLConnection, that makes interacting with servers pretty easy. NSURLConnection follows the system networking preferences, navigates through proxies, and handles other details just as users expect on their devices. But in applications that require a series of server requests and responses, NSURLConnection can be inconvenient to use. All connections made by an application’s class call back into a single set of delegate methods, and when there are numerous connections to be made, sorting out the responses is a bit of a chore.

So ever since Google’s first Mac application, Gmail Notifier, we’ve used a wrapper around NSURLConnection to make it easier to issue http requests. After years of being hidden away and evolving inside of other projects, the Google Toolbox for Mac HTTP Fetcher has now been promoted to its own Google Code open source project. Though simple to use for basic GETs and POSTs, it also offers a variety of convenient features for developers of networking applications.

Here is an example of using the fetcher to make a request of a server:

#import "GTMHTTPFetcher.h"

NSURL *url = [NSURL URLWithString:@"http://www.example.com/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
GTMHTTPFetcher* myFetcher = [GTMHTTPFetcher fetcherWithRequest:request];
[myFetcher beginFetchWithDelegate:self
didFinishSelector:@selector(myFetcher:finishedWithData:error:)];

and when the request is complete, the fetcher invokes a single callback in the application:

- (void)myFetcher:(GTMHTTPFetcher *)fetcher
finishedWithData:(NSData *)retrievedData
error:(NSError *)error {
// if error is not nil, the fetch succeeded
}

One class can initiate many fetches, each with their own callback selectors, making it easy to pack a lot of networking into a single class. In iOS 4 and Mac OS X 10.6, Objective-C blocks simplify fetching even further, avoiding the need for callback methods:

[myFetcher beginFetchWithCompletionHandler:^(NSData *retrievedData,
NSError *error) {
// check the error and use the retrieved data here
}];

As with the underlying NSURLConnection class, the fetcher’s requests are always asynchronous, so the user experience is never blocked waiting for a server response.

This basic http fetcher functionality requires adding just a single source file and header to an application. But the fetcher comes with support for many more advanced features, such as automatic retry on errors, cookie handling, ETag tracking and response caching, convenient request and response logging, and multi-part MIME upload.

To get started using the GTM HTTP Fetcher, read the introduction at the project site, and join the Google Toolbox for Mac discussion group. You can find even more of our open source resources for iOS and Mac developers at the Google Mac Developer Playground.

OAuth Sign-in Controllers for iOS and Mac OS X Applications

Friday, September 10, 2010 at 11:11 AM

By Greg Robbins, Software Engineer

(Editor's note: Long-time readers know we sometimes publish posts aimed at programmers, and this is one of those. If you're not a software developer, don't worry. Our usual non-technical stuff will return.)

It’s rare today for any software to live in isolation. And often, applications want to connect to data in your Google Account. Social networks seek access to your Gmail contacts, finance programs try to sync with your Google Finance portfolio, and photo editing software would like to add eyeglasses and mustaches to the photos in your Picasa Web Albums account. But you probably don’t want your photo editing program to be able to download your financial portfolio, spend money with your Google Checkout account, or have access to any of your other personal data.

The fundamental problem is that giving your username and password to a program hands it access to all of your data. Recently, Internet software developers have converged on a solution called OAuth. When sites and software support OAuth, you only need to give your username and password—your credentials—to the site where your data belongs, and that site passes a token with strictly limited authorization rights back to other sites and software.

For example, if you want to use the new SuperAwesomeEditor application to trim your YouTube videos, the editing program can use OAuth to ask YouTube for permission to edit your videos, and then YouTube will ask you to verify your identify. Once you give your username and password to YouTube, it will hand back to SuperAwesomeEditor a token allowing it access just to your YouTube videos for editing. SuperAwesomeEditor won’t know your password, so it won’t be able to grab your financial documents or check out your Gmail contacts. And tomorrow, if you change your mind, you can tell YouTube to cancel that token, and suddenly SuperAwesomeEditor will be unable to access your videos at all. Now you’re in control of your personal data.

OAuth offers another big advantage: it gives the data provider flexibility in how it authenticates you. So today you may be asked for your username and password, and also to solve a captcha to prove you’re human. Tomorrow, with tighter security, the provider can add another means of authentication, perhaps by sending a text message to your phone with an extra passcode to type when signing in. Improvements in user authentication over time like this aren’t possible in software that only knows how to ask for a username and password.

Unfortunately, the rose of OAuth comes with thorns. One bit of pain is that it takes a lot of tricky programming for applications to use OAuth for authentication. Another downside stems from OAuth having been designed to allow one website to obtain authorization from another; it is not well-suited for use in installed applications, such as native iPhone, iPad, or Mac OS X software.

To encourage adoption of OAuth by Mac and iOS apps, we have released the Google Toolbox for Mac OAuth Controllers. This small set of Objective-C classes makes it easy for developers to add OAuth sign-in embedded into Cocoa apps. Since adoption of OAuth extends beyond Google, the OAuth controllers work with both Google and non-Google data providers.

Here’s how easy it is for developers to let users sign in to Google Contacts with OAuth from an iPhone application:

#import "GTMOAuthViewControllerTouch.h"

NSString *keychainItemName = @"HotSocialNetwork: Google Contacts"
NSString *scope = @"http://www.google.com/m8/feeds/";
// scope for Google Contacts API

GTMOAuthViewControllerTouch *viewController =
[[[GTMOAuthViewControllerTouch alloc] initWithScope:scope
language:nil
appServiceName:keychainItemName
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)]
autorelease];
[[self navigationController] pushViewController:controller animated:YES];

When the user finishes signing in, the controller will invoke the application’s callback method:
                    
- (void)viewController:(GTMOAuthViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuthAuthentication *)auth
error:(NSError *)error {
if (error == nil) {
// Authentication succeeded; retain the auth object
}
}

That’s it. The controllers handle displaying an embedded web view and interacting with the server, and optionally saving the authorization token in the keychain. Later on, the application can use the auth object provided to the callback to authenticate and sign requests it makes to the server, like this:

[auth authorizeRequest:myNSURLMutableRequest];

Authenticating to non-Google services takes a few more lines of code to specify the application’s identity and the server addresses needed for authorization, but it’s almost as simple.



The OAuth protocol is in transition, as a newer version is currently being developed. But if you are a developer, there is already benefit to adopting OAuth for letting your users sign in to Google and other services. For more information about using the GTM OAuth controllers in your app, read the introduction at the project site, and join the discussion group. Google also maintains a site for our ongoing research into OAuth and related subjects.

The OAuth Controllers are an independent sibling project to the Google Toolbox for Mac, a collection of useful classes for iPhone and Mac developers. The controllers incorporate the newly-liberated GTM HTTP Fetcher project, our networking wrapper class, which I’ll discuss in an upcoming post. You can find more of our open-source Mac and iPhone toys on the Google Mac Developer Playground at http://code.google.com/mac.